JS: Intl.NumberFormat

By Xah Lee. Date: .
Intl.NumberFormat
console.log(new Intl.NumberFormat("en-US").format(2418.5335));
// 2,418.534

// or sans new
console.log(Intl.NumberFormat("en-US").format(2418.5335));
// 2,418.534
const xf = new Intl.NumberFormat("en-US", {
 style: "currency",
 currency: "USD",
 minimumFractionDigits: 2,
});
console.log(xf.format(4812.84));
// $4,812.84

// Format as Indian currency (Lakh/Crore system)
const xformat_indian = new Intl.NumberFormat("en-IN", {
 style: "currency",
 currency: "INR",
});
console.log(xformat_indian.format(2745.9071));
// ₹2,745.91
xtodo

Static methods

Intl.NumberFormat.supportedLocalesOf
Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties

Intl.NumberFormat.prototype.constructor

Instance methods

Intl.NumberFormat.prototype.format
Intl.NumberFormat.prototype.formatRange
Intl.NumberFormat.prototype.formatRangeToParts
Intl.NumberFormat.prototype.formatToParts
Intl.NumberFormat.prototype.resolvedOptions

JavaScript. format number