Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Intl.NumberFormat.prototype.format

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

The Intl.NumberFormat.prototype.format property returns a getter function that formats a number according to the locale and formatting options of this NumberFormat object.

Syntax

numberFormat.format(number)

Parameters

number
The number to format.

Description

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

Examples

Using format

Use the function returned by the format getter 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 function returned by the format getter 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 Status Comment
ECMAScript Internationalization API 1.0 (ECMA-402)
The definition of 'Intl.NumberFormat.prototype.format' in that specification.
Standard Initial definition.
ECMAScript Internationalization API 2.0 (ECMA-402)
The definition of 'Intl.NumberFormat.prototype.format' in that specification.
Standard  
ECMAScript Internationalization API 4.0 (ECMA-402)
The definition of 'Intl.NumberFormat.prototype.format' in that specification.
Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 24 29 (29) 11 15 10
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support No support 26 No support No support No support 10

See also

文档标签和贡献者

 此页面的贡献者: abroz, fscholz, Mingun, Sheppy, Norbert
 最后编辑者: abroz,