The Javascript Intl.NumberFormat()
constructor creates objects for Intl.NumberFormat.
We can use Intl.NumberFormat to do language sensitive number formatting.
new Intl.NumberFormat([locales[, options]])
Parameter | Optional | Meaning |
---|---|---|
locales | Optional | A string with a BCP 47 language tag. |
options | Optional | An object with formatting properties. |
options can have the following properties.
Option Meaning localeMatcher The locale matching algorithm to use. Possible values are "lookup" and "best fit" The default is "best fit". style The formatting style to use. Default to "decimal". Possible values: "decimal" for plain number formatting. "currency" for currency formatting. "percent" for percent formatting "unit" for unit formatting numberingSystem Numbering System. Possible values include: "arab", "arabext", " bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", " mong", "mymr", "orya", "tamldec", " telu", "thai", "tibt". unit The unit to use in unit formatting Possible values are core unit identifiers unitDisplay The unit formatting style, default to "short". Possible values: "long" (e.g., 16 litres) "short" (e.g., 16 l) "narrow" (e.g., 16l) currency The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. There is no default value. currencyDisplay How to display the currency in currency formatting. Possible values are "symbol" to use a localized currency symbol "code" to use the ISO currency code, "name" to use a localized currency name such as "dollar" Default to "symbol". useGrouping Whether to use grouping separators Possible values are true and false; the default is true. minimumIntegerDigits The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1. minimumFractionDigits The minimum number of fraction digits to use. Possible values are from 0 to 20; Default for plain number and percent formatting is 0; Default for currency formatting is the number of minor unit digits from currency code. maximumFractionDigits The maximum number of fraction digits to use. Possible values are from 0 to 20; minimumSignificantDigits The minimum number of significant digits to use. Possible values are from 1 to 21; default is 1.//from w ww .j ava 2 s . c om maximumSignificantDigits The maximum number of significant digits to use. Possible values are from 1 to 21; Default is 21. notation The formatting displayed for the number defaults is "standard" "standard" plain number formatting "scientific" the order-of-magnitude for formatted number. "engineering" the exponent of ten when divisible by three "compact" string representing exponent "short" (default) or "long"
var number = 3500;
console.log(new Intl.NumberFormat().format(number));