Intl.NumberFormat.prototype.format()

El m茅todo Intl.NumberFormat.prototype.format() formatea un n煤mero de acuerdo con la configuraci贸n regional y las opciones de formato de este objeto NumberFormat.

Syntax

numberFormat.format(number)

Parametros

number
A Number or BigInt to format.

Descripci贸n

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

Ejemplos

Usando 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 褉褍斜."

Usando format con 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"

Especificaciones

Specification Status Comment
ECMAScript Internationalization API 1.0 (ECMA-402)
La definici贸n de 'Intl.NumberFormat.prototype.format' en esta especificaci贸n.
Standard Initial definition.
ECMAScript Internationalization API 2.0 (ECMA-402)
La definici贸n de 'Intl.NumberFormat.prototype.format' en esta especificaci贸n.
Standard
ECMAScript Internationalization API (ECMA-402)
La definici贸n de 'Intl.NumberFormat.prototype.format' en esta especificaci贸n.
Living Standard

Browser compatibility

BCD tables only load in the browser

See also