Intl.NumberFormat.prototype.format()

The Intl.NumberFormat.prototype.format() method formats a number according to the locale and formatting options of this NumberFormat object.

Syntax

numberFormat.format(number)

Parameters

number
A Number or BigInt to format.

Description

The format getter function formats a number into a string according to the locale and formatting options of this NumberFormat object.

Examples

Using format

Use the format getter function for formatting a single currency value, here for Russia:

var options = { style: 'currency', currency: 'RUB' };
var numberFormat = new Intl.NumberFormat('ru-RU', options);
console.log(numberFormat.format(654321.987));
// → "654 321,99 руб."

Using format with map

Use the format getter function for formatting all numbers in an array. Note that the function is bound to the NumberFormat from which it was obtained, so it can be passed directly to Array.prototype.map.

var a = [123456.789, 987654.321, 456789.123];
var numberFormat = new Intl.NumberFormat('es-ES');
var formatted = a.map(numberFormat.format);
console.log(formatted.join('; '));
// → "123.456,789; 987.654,321; 456.789,123"

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
formatChrome Full support 24Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 15Safari Full support 10WebView Android Full support ≤37Chrome Android Full support 26Firefox Android Full support 56Opera Android Full support 14Safari iOS Full support 10Samsung Internet Android Full support 1.5nodejs Full support Yes

Legend

Full support  
Full support

See also