Intl.NumberFormat.prototype.format

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

* Some parts of this feature may have varying levels of support.

La méthode Intl.NumberFormat.prototype.format() formate un nombre en fonction des options de locales et de formats définis dans l'objet Intl.NumberFormat correspondant.

Exemple interactif

const amount = 654321.987;

const options1 = { style: "currency", currency: "RUB" };
const numberFormat1 = new Intl.NumberFormat("ru-RU", options1);

console.log(numberFormat1.format(amount));
// Expected output: "654 321,99 ₽"

const options2 = { style: "currency", currency: "USD" };
const numberFormat2 = new Intl.NumberFormat("en-US", options2);

console.log(numberFormat2.format(amount));
// Expected output: "$654,321.99"

Syntaxe

js
numberFormat.format(nombre);

Paramètres

nombre

Le nombre qu'on souhaite formater.

Description

La fonction d'accesseur format permet de formater un nombre donné en une chaîne de caractères selon les options de locale et de format de l'objet Intl.NumberFormat.

Exemples

Utiliser format()

On peut utiliser la fonction renvoyée par format pour formater une valeur monétaire selon la locale russe :

js
var options = { style: "currency", currency: "RUB" };
var numberFormat = new Intl.NumberFormat("ru-RU", options);
console.log(numberFormat.format(654321.987));
// → "654 321,99 руб."

Utiliser format() avec map()

On peut également utiliser la fonction format pour formater les nombres contenus dans un tableau. On notera que la fonction est liée à l'objet NumberFormat dont elle provient, on peut donc directement l'utiliser avec Array.prototype.map.

js
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"

Spécifications

Specification
ECMAScript® 2025 Internationalization API Specification
# sec-intl.numberformat.prototype.format

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
format
number param string value is decimal (not Number)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

Voir aussi