JavaScript Intl: Formatting Numbers, Currencies, Dates, Relative Times and Durations for Any Locale
Format values for real users with Intl: locales and options, Intl.NumberFormat for decimals, currencies, percentages, units and compact numbers, Intl.DateTimeFormat with styles and time zones, formatToParts and ranges, RelativeTimeFormat, ListFormat, DurationFormat, and performance tips.
kvi5hnuCode Sprout team member6 min readOn this page
1234567.891 is one number, but people write it as 1,234,567.891, 1.234.567,891, 12,34,567.891 or ١٬٢٣٤٬٥٦٧٫٨٩١ depending on where they live. Dates, currencies, lists and "3 days ago" vary just as much. The built-in Intl object (ECMAScript's Internationalization API) formats all of these correctly for hundreds of locales, using the Unicode CLDR data built into browsers and Node. No library needed.

Locales and options
Every Intl formatter takes the same two arguments:
new Intl.NumberFormat(locales, options)
localesis a BCP 47 language tag like"en-US","de-DE","pt-BR"or"hi-IN"(language, optional script, optional region), or an array of them in order of preference. Omit it (or passundefined) to use the user's default locale: the browser's language setting or the server's configuration. In browsers,navigator.languageandnavigator.languagestell you the user's preferences.optionsis an object controlling the output.
Create a formatter once and call its format method many times. The toLocaleString methods on numbers and dates are convenient shortcuts that create a formatter on each call.
Intl.NumberFormat
const n = 1234567.891;
console.log(new Intl.NumberFormat("en-US").format(n));
console.log(new Intl.NumberFormat("de-DE").format(n));
console.log(new Intl.NumberFormat("en-IN").format(n));
console.log(n.toLocaleString("en-US", { maximumFractionDigits: 1 }));
1,234,567.891
1.234.567,891
12,34,567.891
1,234,567.9
Currency
const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
console.log(usd.format(42.5), usd.format(-1234.567));
console.log(new Intl.NumberFormat("ja-JP", { style: "currency", currency: "JPY" }).format(4200));
console.log(new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR" }).format(123456.5));
const accounting = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", currencySign: "accounting" });
console.log(accounting.format(-5));
$42.50 -$1,234.57
¥4,200
₹1,23,456.50
($5.00)
currencyis required withstyle: "currency"; it's an ISO 4217 code. The locale controls how it's written, the currency controls which symbol and how many decimals (yen has none).- Formatting rounds for display only. Do the money math in integer cents or with a decimal library (article 12).
- Other options:
currencyDisplay: "code" | "name" | "narrowSymbol".
Some locales use special spaces. German writes 42,50 € with a no-break space (U+00A0) before the euro sign, and French groups digits with a narrow no-break space (U+202F). They look like normal spaces but aren't, which is a classic cause of failing tests and broken string comparisons. Compare numbers, not formatted strings, and avoid hard-coding formatted output in tests.
Percentages, units and compact notation
const fmt = (options, value) => new Intl.NumberFormat("en-US", options).format(value);
console.log(fmt({ style: "percent", maximumFractionDigits: 1 }, 0.4567));
console.log(fmt({ style: "unit", unit: "kilometer-per-hour" }, 88));
console.log(fmt({ style: "unit", unit: "megabyte", unitDisplay: "narrow" }, 512));
console.log(fmt({ notation: "compact" }, 1234567), fmt({ notation: "compact", compactDisplay: "long" }, 2500));
console.log(fmt({ notation: "scientific" }, 123456));
console.log(fmt({ signDisplay: "always" }, 5), fmt({ signDisplay: "exceptZero" }, 0));
45.7%
88 km/h
512MB
1.2M 2.5 thousand
1.235E5
+5 0
style: "percent" multiplies by 100. Units include byte, kilobyte, meter, kilogram, celsius, liter, second, hour and more, and they can be combined with -per-.
Controlling digits
const fmt = (options, value) => new Intl.NumberFormat("en-US", options).format(value);
console.log(fmt({ minimumFractionDigits: 2, maximumFractionDigits: 2 }, 3));
console.log(fmt({ maximumFractionDigits: 0 }, 2.5), fmt({ maximumFractionDigits: 0 }, 3.5));
console.log(fmt({ maximumSignificantDigits: 3 }, 123456));
console.log(fmt({ useGrouping: false }, 1234567));
console.log(fmt({ maximumFractionDigits: 0, roundingMode: "floor" }, 2.9));
3.00
3 4
123,000
1234567
2
The default rounding is "half expand" (0.5 rounds away from zero), unlike toFixed, which has binary-precision surprises. roundingMode (ES2023) offers ceil, floor, trunc, halfEven and more.
formatToParts
formatToParts returns the pieces with their types, so you can style them separately (for example, a smaller currency symbol):
const parts = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).formatToParts(-1234.5);
console.log(parts.map((p) => `${p.type}:${p.value}`).join(" | "));
minusSign:- | currency:$ | integer:1 | group:, | integer:234 | decimal:. | fraction:50
formatRange(start, end) formats ranges like "5.00" with the right separator for the locale.
Intl.DateTimeFormat
const d = new Date(Date.UTC(2026, 10, 18, 9, 30));
for (const locale of ["en-US", "en-GB", "de-DE", "ja-JP"]) {
console.log(locale, new Intl.DateTimeFormat(locale, { timeZone: "UTC" }).format(d));
}
en-US 11/18/2026
en-GB 18/11/2026
de-DE 18.11.2026
ja-JP 2026/11/18
The same short date means November 18 to one reader and is unreadable to another. "11/12/2026" is November 12 in the US and 11 December in the UK. Always format dates for the reader's locale, or use unambiguous formats.
Styles, components and time zones
const d = new Date(Date.UTC(2026, 10, 18, 9, 30));
console.log(new Intl.DateTimeFormat("en-US", {
dateStyle: "full", timeStyle: "short", timeZone: "America/New_York",
}).format(d));
console.log(new Intl.DateTimeFormat("en-US", {
weekday: "short", month: "long", day: "numeric",
hour: "2-digit", minute: "2-digit", hourCycle: "h23",
timeZone: "Asia/Kolkata", timeZoneName: "short",
}).format(d));
Wednesday, November 18, 2026 at 4:30 AM
Wed, November 18 at 15:00 GMT+5:30
dateStyle/timeStyle("full","long","medium","short") give the locale's standard formats. They can't be mixed with individual components.- Components (
year,month,day,weekday,hour,minute,second,fractionalSecondDigits,timeZoneName) request specific fields; the locale still decides order and punctuation. timeZone(an IANA name such as"Europe/Paris") displays the instant in that zone. Without it, the user's own zone is used.hourCycle("h12","h23") orhour12overrides 12/24-hour display.
formatToParts and formatRange work for dates too, and Temporal objects format with the same options (article 84).
Intl.RelativeTimeFormat: "3 days ago"
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
console.log(rtf.format(-1, "day"), "|", rtf.format(0, "day"), "|", rtf.format(2, "week"));
console.log(new Intl.RelativeTimeFormat("en").format(-1, "day"));
console.log(new Intl.RelativeTimeFormat("es", { numeric: "auto" }).format(1, "day"));
yesterday | today | in 2 weeks
1 day ago
mañana
It formats a number and unit you supply; it doesn't compute the difference. A small helper picks the unit:
function timeAgo(from, to, locale = "en") {
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
const seconds = Math.round((from - to) / 1000);
const units = [["year", 31536000], ["month", 2592000], ["week", 604800], ["day", 86400], ["hour", 3600], ["minute", 60]];
for (const [unit, size] of units) {
if (Math.abs(seconds) >= size) return rtf.format(Math.round(seconds / size), unit);
}
return rtf.format(seconds, "second");
}
const now = Date.UTC(2026, 10, 18, 12);
console.log(timeAgo(now - 125_000, now), "|", timeAgo(now - 3 * 86_400_000, now), "|", timeAgo(now + 7200_000, now));
2 minutes ago | 3 days ago | in 2 hours
Intl.ListFormat: "a, b, and c"
console.log(new Intl.ListFormat("en", { type: "conjunction" }).format(["red", "green", "blue"]));
console.log(new Intl.ListFormat("en-GB").format(["red", "green", "blue"]));
console.log(new Intl.ListFormat("en", { type: "disjunction" }).format(["tea", "coffee"]));
console.log(new Intl.ListFormat("de").format(["Rot", "Grün", "Blau"]));
red, green, and blue
red, green and blue
tea or coffee
Rot, Grün und Blau
Note the serial ("Oxford") comma in US English and its absence in British English: details you'd never get right for every language by hand.
Intl.DurationFormat (ES2025)
console.log(new Intl.DurationFormat("en", { style: "long" }).format({ hours: 2, minutes: 30 }));
console.log(new Intl.DurationFormat("en", { style: "digital" }).format({ hours: 1, minutes: 5, seconds: 9 }));
2 hours, 30 minutes
1:05:09
It accepts a plain object with duration fields or a Temporal.Duration.
Performance and practical tips
- Reuse formatters. Creating one loads and processes locale data. In a loop or table, create it once outside:
const fmt = new Intl.NumberFormat(...), thenrows.map((r) => fmt.format(r.total)).toLocaleStringinside a big loop is noticeably slower. - Pass the user's locale explicitly when you know it (from settings or
Accept-Languageon a server), so server-rendered and browser-rendered output agree. - Don't parse formatted strings. Intl formats; it doesn't parse. Keep the raw value alongside the display string.
- Don't snapshot exact output in tests. CLDR data improves with browser and Node updates, and spaces may be special characters. Test with
formatToParts, or with values formatted by the same API. resolvedOptions()shows what a formatter actually uses:new Intl.DateTimeFormat().resolvedOptions().timeZoneis a reliable way to get the user's time zone.
Common questions
Why does toLocaleString() give different results on my laptop and the server?
Without a locale argument, it uses the default locale and time zone of the machine running it. Pass locales and timeZone explicitly when the output must be consistent.
How do I format a number with exactly two decimals?
new Intl.NumberFormat(locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(x)
Unlike toFixed(2), it also adds locale-appropriate grouping and decimal separators.
Can Intl translate my app's text?
No. Intl formats values (numbers, dates, lists, plurals, names of languages and regions). Translating your own sentences needs a message-translation library or the platform's i18n tools; Intl provides building blocks those tools use, like plural rules (next article).
Is Intl available everywhere?
Yes. All current browsers and Node.js ship full locale data. DurationFormat is the newest piece (ES2025); check support if you target older browsers.
Summary
Intlformatters take a BCP 47localesargument and anoptionsobject; reuse formatter instances.Intl.NumberFormathandles decimals, currencies (style: "currency"plus an ISO code), percentages, units, compact and scientific notation, digit and rounding control,formatToPartsand ranges.Intl.DateTimeFormathandlesdateStyle/timeStyleor individual components,timeZone,hourCycle, parts and ranges.RelativeTimeFormatformats "in 2 weeks"/"yesterday",ListFormatjoins lists naturally, andDurationFormatformats durations.- Some locales use no-break spaces; never parse formatted output or hard-code it in tests.
Practice Questions
Format 0.075 as a percentage with one decimal place in US English.
Answer
new Intl.NumberFormat("en-US", { style: "percent", minimumFractionDigits: 1 }).format(0.075)
Gives "7.5%".
Show the instant 2026-11-18T09:30:00Z as a time in Tokyo, 24-hour format.
Answer
new Intl.DateTimeFormat("en-US", { timeZone: "Asia/Tokyo", hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).format(new Date("2026-11-18T09:30:00Z"))
Gives "18:30".
What's wrong with this code for 10,000 items?
items.map((x) => x.price.toLocaleString("de-DE", { style: "currency", currency: "EUR" }))
Answer
It creates a new formatter for every item. Create one Intl.NumberFormat before the loop and call its format method.
Why might expect(fmt.format(42.5)).toBe("42,50 €") fail in a German-locale test?
Answer
The real output uses a no-break space (U+00A0) between the number and the euro sign, not a normal space. Compare against output built the same way, or check formatToParts.
Previous: Temporal in JavaScript: PlainDate, ZonedDateTime, Instant, Durations and Replacing Date
Next: JavaScript Intl for Text: Sorting with Collator, Plural Rules, Segmenter, Display Names and Locales

More in JavaScript Course
Quiz: Modern JavaScript, ES2022 to ES2027 Features
Twenty-four questions on what's new in JavaScript: change-array-by-copy methods, groupBy, Set methods, iterator helpers, Promise.withResolvers and Promise.try, RegExp.escape and the v flag, using declarations, Error.isError, Base64 typed arrays, Temporal, getOrInsert and Iterator.zip.
Quiz: JavaScript's Delicate Details (Spec-Level Edge Cases)
Twenty-eight questions on the fine print of JavaScript, drawn from the ECMAScript specification and MDN: sparse arrays, -0, number limits, JSON edge cases, Date overflow, UTF-16, property attributes, inherited accessors, comparison quirks, labels, regex state and Symbol.toPrimitive.
Quiz: JavaScript Interview Questions (Output Prediction and Core Concepts)
Thirty classic JavaScript interview questions: closures in loops, hoisting and the TDZ, this, the event loop and microtasks, async/await, coercion, sorting and parseInt traps, prototypes, copying, finally, generators and bind. Every answer was verified by running it.
Quiz: JavaScript Course Final Exam (All 17 Parts)
The final exam for the JavaScript course: thirty questions spanning all seventeen parts, from syntax, types and operators through objects, arrays, functions, classes, modules, the standard library, iterators, async code, metaprogramming, browsers, Node.js and tooling.
Discussion
Sign in to ask a question or share what you learned.