W3cubDocs

/JavaScript

Intl.numberFormat.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. This is considered a historical artefact, as part of a convention which is no longer followed for new features, but is preserved to maintain compatibility with existing programs.

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

Specifications

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
format 24 12
12
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".
29 11
11
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".
15 10
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
format 4.4 25 56 14 10 1.5
Server
Node.js
format 0.12
0.12
Before version 13.0.0, only the locale data for en-US is available by default. See the NumberFormat() constructor for more details.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format