Javascript Intl.NumberFormat format()

Introduction

The Javascript Intl.NumberFormat format() method formats a number.

It formats a number according to the locale and formatting options.

numberFormat.format(number)
Parameter Optional Meaning
number Required A Number or BigInt to format.

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

var options = { style: 'currency', currency: 'RUB' };
var numberFormat = new Intl.NumberFormat('ru-RU', options);
console.log(numberFormat.format(654321.987));

NumberFormat outputs localized strings:

var number = 3500;

var formatter = new Intl.NumberFormat('de-DE', {
  style: 'currency',
  currency: 'EUR'
});/*www . j ava2s.c  o m*/

let a = formatter.format(number);
console.log(a);

Using format with map

var a = [123456.789, 987654.321, 34567.123];
var numberFormat = new Intl.NumberFormat('es-ES');
var formatted = a.map(numberFormat.format);
console.log(formatted.join('; '));



PreviousNext

Related