new Intl.NumberFormat(locales, options) builds a formatter for numbers. Call format(value) to get a locale string with the right grouping and decimal marks.
Options can switch to style: "currency" or style: "percent" for money and percentages.
Remember
new Intl.NumberFormat(locales, options)
fmt.format(number)
style: "decimal" | "currency" | "percent"
currency: "USD" when style is currency
Syntax
Create a NumberFormat, then call format with a number.
JavaScript
const fmt = new Intl.NumberFormat("en-US");
console.log(fmt.format(1234567.89));
// ECMAScript 2015 — Intl.NumberFormat
new Intl.NumberFormat(locales, options)
fmt.format(value)
// options.style : "decimal" | "currency" | "percent" | ...
// options.currency : ISO code when style is "currency"
Parameters
Parameter
Description
locales
Optional. Locale string or list, such as "en-US" or "de-DE".
options
Optional. Style, currency, fraction digits and more.
value
For format: the number to format.
Return Value
Return Value
Description
NumberFormat object
From the constructor.
string
From format: the localized number text.
JavaScript Examples
Example 1 — Same Number, Two Locales
Format 1234567.89 in American and German styles.
JavaScript
const n = 1234567.89;
console.log("en-US: " + new Intl.NumberFormat("en-US").format(n));
console.log("de-DE: " + new Intl.NumberFormat("de-DE").format(n));