new Intl.NumberFormat(locales, options) formats numbers and BigInts. The style option picks decimal (default), currency (with currency), percent or unit (with unit). Other options set notation (compact, scientific, engineering), signDisplay, useGrouping, currencyDisplay (symbol, code, name) and rounding through minimumFractionDigits, maximumFractionDigits or significant digits. formatToParts() returns typed pieces for custom styling, and formatRange(3, 5) prints a range such as "€3.00 – €5.00".
const n = 1234567.891;
for (const locale of ['en-US', 'de-DE', 'en-IN', 'ar-EG', 'zh-CN-u-nu-hanidec']) {
console.log(locale.padEnd(19), new Intl.NumberFormat(locale).format(n));
}
const money = (l, c) => new Intl.NumberFormat(l, { style: 'currency', currency: c }).format(n);
console.log(money('en-US', 'USD'), '|', money('de-DE', 'EUR'), '|', money('ja-JP', 'JPY'));
console.log(new Intl.NumberFormat('en', { notation: 'compact' }).format(n),
new Intl.NumberFormat('ja', { notation: 'compact' }).format(n),
new Intl.NumberFormat('en', { style: 'unit', unit: 'kilometer-per-hour' }).format(88),
new Intl.NumberFormat('en', { style: 'percent', signDisplay: 'always' }).format(0.256));en-US 1,234,567.891 de-DE 1.234.567,891 en-IN 12,34,567.891 ar-EG ١٬٢٣٤٬٥٦٧٫٨٩١ zh-CN-u-nu-hanidec 一,二三四,五六七.八九一 $1,234,567.89 | 1.234.567,89 € | ¥1,234,568 1.2M 123万 88 km/h +26%
Plain numbers keep up to three fraction digits; currencies round to their minor unit, which for the yen is none. Indian English groups by lakh and crore. Store and transmit raw numbers and never parse formatted text back.