Intl.NumberFormat

The Intl.NumberFormat object is a constructor for objects that enable language sensitive number formatting.

Constructor

Intl.NumberFormat()
Creates a new NumberFormat object.

Static methods

Intl.NumberFormat.supportedLocalesOf()
Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance methods

Intl.NumberFormat.prototype.format()
Getter function that formats a number according to the locale and formatting options of this NumberFormat object.
Intl.NumberFormat.prototype.formatToParts()
Returns an Array of objects representing the number string in parts that can be used for custom locale-aware formatting.
Intl.NumberFormat.prototype.resolvedOptions()
Returns a new object with properties reflecting the locale and collation options computed during initialization of the object.

Examples

Basic usage

In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.

var number = 3500;

console.log(new Intl.NumberFormat().format(number));
// β†’ '3,500' if in US English locale

Using locales

This example shows some of the variations in localized number formats. In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument:

var number = 123456.789;

// German uses comma as decimal separator and period for thousands
console.log(new Intl.NumberFormat('de-DE').format(number));
// β†’ 123.456,789

// Arabic in most Arabic speaking countries uses real Arabic digits
console.log(new Intl.NumberFormat('ar-EG').format(number));
// β†’ Ω‘Ω’Ω£Ω€Ω₯Ω¦Ω«Ω§Ω¨Ω©

// India uses thousands/lakh/crore separators
console.log(new Intl.NumberFormat('en-IN').format(number));
// β†’ 1,23,456.789

// the nu extension key requests a numbering system, e.g. Chinese decimal
console.log(new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec').format(number));
// β†’ δΈ€δΊŒδΈ‰,ε››δΊ”ε…­.七八九

// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
console.log(new Intl.NumberFormat(['ban', 'id']).format(number));
// β†’ 123.456,789

Using options

The results can be customized using the options argument:

var number = 123456.789;

// request a currency format
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// β†’ 123.456,79 €

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// β†’ οΏ₯123,457

// limit to three significant digits
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
// β†’ 1,23,000

Using style and unit

console.log(new Intl.NumberFormat("pt-PT",  {
    style: 'unit',
    unit: "mile-per-hour"
}).format(50));
// β†’ 50 mi/h

console.log((16).toLocaleString('en-GB', {
    style: "unit",
    unit: "liter",
    unitDisplay: "long"
}));
// β†’ 16 litres

Specifications

Specification
ECMAScript Internationalization API (ECMA-402)
The definition of 'Intl.NumberFormat' in that specification.

Browser compatibility

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
NumberFormatChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support 0.12
Notes
Full support 0.12
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the NumberFormat() constructor for more details.
NumberFormat() constructorChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support 13.0.0
Full support 13.0.0
Partial support 0.12
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the NumberFormat instance silently falls back to en-US. To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
formatChrome Full support 24Edge Full support 12
Notes
Full support 12
Notes
Notes Before Edge 18, numbers are rounded to 15 decimal digits. For example, new Intl.NumberFormat('en-US').format(1000000000000005) returns "1,000,000,000,000,010".
Firefox Full support 29IE Full support 11
Notes
Full support 11
Notes
Notes In Internet Explorer 11, numbers are rounded to 15 decimal digits. For example, new Intl.NumberFormat('en-US').format(1000000000000005) returns "1,000,000,000,000,010".
Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support 0.12
Notes
Full support 0.12
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the NumberFormat() constructor for more details.
formatToParts
Experimental
Chrome Full support 64Edge Full support 12Firefox Full support 58IE No support NoOpera Full support 51Safari Full support 13WebView Android Full support 64Chrome Android Full support 64Firefox Android Full support 58Opera Android Full support 47Safari iOS Full support 13Samsung Internet Android Full support 9.0nodejs Full support 10.0.0
Notes
Full support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the NumberFormat() constructor for more details.
resolvedOptionsChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support 0.12
Notes
Full support 0.12
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the NumberFormat() constructor for more details.
supportedLocalesOfChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support 13.0.0
Full support 13.0.0
Partial support 0.12
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.

Legend

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also