Web/JavaScript/Reference/Global objects/Intl/NumberFormat/format
The Intl.NumberFormat.prototype.format() method formats a number according to the locale and formatting options of this NumberFormat object.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
numberFormat.format(number)
Parameters
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
| Specification |
| ECMAScript Internationalization API (ECMA-402)The definition of 'Intl.NumberFormat.prototype.format' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
format
|
Chrome
Full support 24 |
Edge Full support 12 Full support 12 Notes' Before Edge 18, numbers are rounded to 15 decimal digits. For example, |
Firefox
Full support 29 |
IE Full support 11 Full support 11 Notes' In Internet Explorer 11, numbers are rounded to 15 decimal digits. For example, |
Opera
Full support 15 |
Safari
Full support 10 |
WebView Android
Full support 4.4 |
Chrome Android
Full support 25 |
Firefox Android
Full support 56 |
Opera Android
Full support 14 |
Safari iOS
Full support 10 |
Samsung Internet Android
Full support 1.5 |
nodejs Full support 0.12 Full support 0.12 Notes' Before version 13.0.0, only the locale data for |
Legend
- Full support
- Full support
- See implementation notes.'
- See implementation notes.
See also
Intl.NumberFormat.prototype.format() by Mozilla Contributors is licensed under CC-BY-SA 2.5.