Mrs. Sri's database used to keep the price as the text "$70.00". It looks tidy, until she wants to add up the total for 3 nights, or write the same price for an Indonesian guest. Prices, dates and times are written differently in every country, though the values are the same. The rule: store raw values, format at the edge. In Mrs. Sri's ledger, the price is written plainly as 70 and the check-in time in UTC. Every guest gets a copy rewritten in their own habits: "$70.00" for an American guest, "US$70,00" for an Indonesian one, and the same 14:00 at the homestay written as 15:00 in Tokyo. The Intl API lesson introduced the formatters; here we go into their options.
Store raw, format at the edge
// In the database and the API: numbers and UTC times, not finished text
const booking = { pricePerNight: 35, nights: 2, checkIn: '2026-12-12T06:00:00Z' };
// On screen: format with the guest's locale and the zone where it happens
const total = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
.format(booking.pricePerNight * booking.nights); // "$70.00"
const when = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'short', timeZone: 'Asia/Singapore' })
.format(new Date(booking.checkIn)); // "Saturday, December 12, 2026 at 2:00 PM"
- The price is stored as a number; the text "$70.00" can't be added up and can't be rewritten for another locale.
- Time is stored as a UTC instant (ISO 8601 with
Zor an offset). Careful when parsing:new Date('2026-12-12')is read as UTC midnight, so a laptop in Los Angeles writes "December 11, 2026".new Date('2026-12-12T14:00')with no offset is read as the machine's local time: 06:00 UTC on a laptop set to the homestay's zone, 14:00 UTC on a UTC server. Write the offset:'2026-12-12T14:00:00+08:00'.
Currency: symbol, narrowSymbol, code, name
currencyDisplay picks how the currency is written. The room price in US dollars, plus sample amounts in other currencies (not exchange rates):
currencyDisplay |
en-US, USD 70 |
id-ID, USD 70 |
en-US, JPY 6500 |
ja-JP, JPY 6500 |
en-US, EGP 2150 |
|---|---|---|---|---|---|
symbol (default) |
$70.00 | US$70,00 | ¥6,500 | ¥6,500 | EGP 2,150.00 |
narrowSymbol |
$70.00 | $70,00 | ¥6,500 | ¥6,500 | E£2,150.00 |
code |
USD 70.00 | USD 70,00 | JPY 6,500 | JPY 6,500 | EGP 2,150.00 |
name |
70.00 US dollars | 70,00 Dolar Amerika Serikat | 6,500 Japanese yen | 6,500円 | 2,150.00 Egyptian pounds |
symboldepends on the locale: a bare "$" means US dollars inen-US, but inid-IDthe US dollar is written "US$".narrowSymbolshortens it, but "$" is also the Australian and Singapore dollar, so it's ambiguous on an international price list.- Yen:
ja-JPwrites "¥6,500", but Safari writes "¥6,500", andnamewrites "6,500円". The Egyptian pound inar-EG: "٢٬١٥٠٫٠٠ ج.م.". - Decimals follow the currency: USD and EGP 2 digits, JPY 0 digits in every engine.
- Some currencies get different decimals in different engines. The Indonesian rupiah, for guests who want prices in their own currency: always
maximumFractionDigits: 0. The default IDR decimals are 2 in Chrome 147, Firefox 146 and Safari 26.4, but 0 in Node 22.22.1 (CLDR 48) and Chrome 156.minimumFractionDigits: 0alone isn't enough: for 349999.5 Firefox and Safari write "Rp 349.999,5", whilemaximumFractionDigits: 0rounds to "Rp 350.000".
Compact notation and units
new Intl.NumberFormat('en-US', { notation: 'compact' }).format(1200000); // "1.2M"
new Intl.NumberFormat('en-US', { notation: 'compact', compactDisplay: 'long' }).format(1200000); // "1.2 million"
new Intl.NumberFormat('en-US', { style: 'unit', unit: 'kilometer', unitDisplay: 'long' }).format(26); // "26 kilometers"
new Intl.NumberFormat('en-US', { style: 'unit', unit: 'celsius' }).format(12); // "12°C"
- 1,200,000 is written "1.2M" (
en-US), "1,2 jt" (id-ID), "120万" (ja-JP, 万 = 10,000) and "١٫٢ مليون" (ar-EG). - Compact notation rounds to about two significant digits: 1,050,000 becomes "1.1M"; 1,275,000 becomes "1.3M". Fine for "1.3M views", never for an amount to pay.
style: 'unit'takes official unit names:kilometer,celsius,meter,day. The homestay at 2,093 m: "2,093 m" (en-US), "٢٬٠٩٣ مترًا" (ar-EG).unit: 'day'withunitDisplay: 'long'for 2 gives "2 days", "2 hari", and the dual form "يومان" inar-EG. There is nonightunit:RangeError.
Dates: dateStyle or one field at a time
| Options | en-US |
id-ID |
ja-JP |
ar-EG |
|---|---|---|---|---|
dateStyle: 'short' |
12/12/26 | 12/12/26 | 2026/12/12 | ١٢/١٢/٢٠٢٦ |
dateStyle: 'medium' |
Dec 12, 2026 | 12 Des 2026 | 2026/12/12 | ١٢/١٢/٢٠٢٦ |
dateStyle: 'long' |
December 12, 2026 | 12 Desember 2026 | 2026年12月12日 | ١٢ ديسمبر ٢٠٢٦ |
{ weekday: 'short', day: 'numeric', month: 'short' } |
Sat, Dec 12 | Sab, 12 Des | 12月12日(土) | السبت، ١٢ ديسمبر |
dateStyleandtimeStyleare ready-made packages. Fields (weekday,day,month,year,hour,minute) choose which parts appear; their order and punctuation still come from the locale.- The two can't be mixed:
{ dateStyle: 'medium', weekday: 'short' }throws aTypeError, with a different message in every engine.
Ranges and relative time
const checkIn = new Date('2026-12-12T06:00:00Z'); // Saturday 14:00 at the homestay
const checkOut = new Date('2026-12-14T04:00:00Z'); // Monday 12:00 at the homestay
new Intl.DateTimeFormat('en-US', { day: 'numeric', month: 'short', timeZone: 'Asia/Singapore' }).formatRange(checkIn, checkOut);
// "Dec 12\u2009\u2013\u200914" in Node and Chromium 147, "Dec 12 \u2013 14" in Chromium 156, Firefox and Safari (\u2013 is the en dash)
// id-ID: "12\u201314 Des"
// ja-JP: "12/12~12/14", Firefox "12月12日~14日"; ar-EG: "١٢\u2013١٤ ديسمبر"
const rtf = new Intl.RelativeTimeFormat('en-US', { numeric: 'auto' });
rtf.format(3, 'day'); // "in 3 days"
rtf.format(1, 'day'); // "tomorrow"
formatRangewrites the shared part only once: "Dec 12" to "14", not "Dec 12" to "Dec 14". Across years it writes both in full: "Dec 30, 2026", a dash, "Jan 2, 2027".- The result contains U+2013 and, in Node and Chromium 147, the thin space U+2009. Don't compare it with typed text.
RelativeTimeFormatonly writes the difference you compute. "Check-in in 3 days" is written by Intl as "in 3 days" (en-US), "dalam 3 hari", "3 日後", "خلال ٣ أيام". Count the difference in calendar days in Asia/Singapore (take year, month and day throughformatToPartswithtimeZone), not hours divided by 24.
One instant, three wall clocks
Mrs. Sri's check-in falls at 2026-12-12T06:00:00Z, 14:00 at the homestay (Asia/Singapore). Before you look at the results, guess: a guest in Cairo who formats it with timeZone: 'Africa/Cairo' sees what time? And is it the same hour if the date is 12 July?
const fmt = (zone) => new Intl.DateTimeFormat('en-US', { weekday: 'short', day: 'numeric', month: 'short', hour: 'numeric', minute: '2-digit', timeZoneName: 'short', timeZone: zone }).format(checkIn);
fmt('Asia/Singapore'); // "Sat, Dec 12, 2:00 PM GMT+8"
fmt('Asia/Tokyo'); // "Sat, Dec 12, 3:00 PM GMT+9" (ja-JP writes "JST")
fmt('Africa/Cairo'); // "Sat, Dec 12, 8:00 AM GMT+2"
Cairo shows 8:00 AM, because in December Egypt is on UTC+2. Egypt uses summer time, so for 12 July the offset is GMT+03:00 and the hour is 9:00 AM. So never store "UTC+2" as a zone; store the IANA name (Africa/Cairo) and let Intl work it out. "SGT" isn't a zone name either: timeZone: 'SGT' throws a RangeError. For a check-in schedule, write the time in the homestay's zone (Asia/Singapore); the time in the guest's zone may be added as a note.
📌 How the engines differ, measured
Measured in Chromium 147, Firefox 146, WebKit 26.4 and Node 22.22.1. Anything not in this table was the same in all four.
| Measured | Chromium 147 | Firefox 146 | WebKit 26.4 | Node 22.22.1 |
|---|---|---|---|---|
| Default IDR decimals | 2 | 2 | 2 | 0 |
IDR 349999.5 with only minimumFractionDigits: 0 |
Rp 349.999,5 | Rp 349.999,5 | Rp349.999,5 | Rp 350.000 |
JPY symbol in ja-JP |
¥ | ¥ | ¥ | ¥ |
Spaces in an en-US range |
U+2009 | plain spaces | plain spaces | U+2009 |
ja-JP range |
12/12~12/14 | 12月12日~14日 | 12/12~12/14 | 12/12~12/14 |
weekday: 'short' in ar-EG |
السبت | السبت | سبت | السبت |
TypeError message for dateStyle plus weekday |
Invalid option : option | can't set option weekday when dateStyle is used | dateStyle and timeStyle may not be used with other DateTimeFormat options | Invalid option : option |
unit: 'day', long, ja-JP |
2 日 | 2 日 | 2日 | 2 日 |
weekday plus hour in en-US |
Sat, Dec 12, 2:00 PM | Sat, Dec 12, 2:00 PM | Sat, Dec 12 at 2:00 PM | Sat, Dec 12, 2:00 PM |
We measured again on 29 October 2026 with Chromium 156.0.8078.4 and Firefox 148.0.2 from Playwright. Firefox 148 matches the Firefox 146 column exactly. Chromium 156 differs in three rows: the default IDR decimals are now 0, 349999.5 becomes "Rp 350.000", and an en-US range uses plain spaces.
⚠️ Why is the price or the time off?
- Storing finished text. "$70.00" or "12/12/2026" in the database can't be computed with or translated. Store numbers and UTC times.
- Compact notation for prices. "$1.1M" is not $1,050,000.
narrowSymbolon an international price list. "$" could be any dollar; usesymbolorcode.- Forgetting
timeZone, or writing a fixed offset. The hour follows the device's zone, and Cairo's offset changes between December and July.
TL;DR: Store prices as numbers (70) and times as UTC (2026-12-12T06:00:00Z), then format on screen. Currency uses { style: "currency", currency: "USD" } plus currencyDisplay (symbol "$70.00", or "US$70,00" in id-ID, narrowSymbol "$", code "USD", name "US dollars"). A currency whose decimals differ by engine needs maximumFractionDigits: 0: the rupiah's default decimals are 2 in Firefox, Safari and Chrome 147 but 0 in Node 22 and Chrome 156. The en-US locale writes 1000000 as "1,000,000". Compact notation ("1.2M", "1,2 jt", "120万") rounds, so it's not for prices. style: 'unit' for km, °C and days. Dates use dateStyle or fields, never both. formatRange writes "Dec 12 to 14" with the U+2013 dash, RelativeTimeFormat writes "in 3 days". The same check-in is 14:00 in Asia/Singapore, 15:00 in Asia/Tokyo and 08:00 in Africa/Cairo (09:00 in July); store the IANA zone name, not an offset.
⚡ Store raw, format at the edge
Write:
// In the database and the API: numbers and UTC times, not finished text
const booking = { pricePerNight: 35, nights: 2, checkIn: '2026-12-12T06:00:00Z' };
Meaning: The price is stored as a number, time as a UTC instant. The text "$70.00" can't be added up and can't be rewritten for another locale.
⚡ Dollars in the en-US locale
Write:
const total = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
.format(booking.pricePerNight * booking.nights); // "$70.00"
Guess first: how does the en-US locale write 1000000?
1,000,000, with a comma as the thousands separator. An Indonesian guest gets US$70,00, with a comma before the cents.
Meaning: The locale decides the thousands and decimal separators. The currency decides the decimals: 2 for US dollars, in every engine.
⚡ One instant, three wall clocks
Meaning: The check-in 2026-12-12T06:00:00Z is 14:00 in Asia/Singapore, 15:00 in Asia/Tokyo and 08:00 in Africa/Cairo (09:00 in July, because of summer time). So store the IANA zone name, not an offset. timeZone: 'SGT' even throws a RangeError.