Number.prototype.toLocaleString()
A full Intl.NumberFormat behind a method call. If a number is going to be read by a human, this or Intl is the answer — toFixed is not.
Demo
The first two cases are the reason this method exists: en-US writes 1,234.5 while de-DE writes 1.234,5 — the separators are exactly swapped. Hard-coding either one is wrong for most of the world. The en-IN case shows grouping is not always in threes; Indian numbering groups the leading digits in pairs. The last case is the default worth knowing: without options the maximum fraction digits is THREE, so a value with more decimals is silently rounded for display.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| locales | string | string[] | no (host default) | A BCP 47 tag such as "en-US" or "de-DE". Omitted, the runtime locale is used — which differs between your machine and your users. |
| options | object | no ({}) | Intl.NumberFormat options — style (decimal, currency, percent, unit), currency, minimumFractionDigits, maximumFractionDigits, notation, useGrouping. |
Return value
string — The number formatted for the given locale — digit grouping, the right decimal separator, and optionally a currency symbol or percent sign.
Common patterns
price.toLocaleString('en-US', {style: 'currency', currency: 'USD'});
(0.25).toLocaleString('en-US', {style: 'percent'});
const f = new Intl.NumberFormat('en-US'); rows.map(r => f.format(r.value));
Examples
Pitfalls
(1.23456789).toLocaleString('en-US')
(1.23456789).toLocaleString('en-US', {maximumFractionDigits: 8})
(1234.5).toLocaleString()
(1234.5).toLocaleString('en-US')
parseFloat((1234.5).toLocaleString('en-US'))
const n = 1234.5; // format only for display
rows.map(r => r.n.toLocaleString("en-US"))
const f = new Intl.NumberFormat("en-US"); rows.map(r => f.format(r.n));
When to use
- Any number a person will read
- Currency, percentages and units
- Digit grouping that follows the reader conventions
- Compact notation for large numbers, via the notation option
- Machine-readable output → toFixed or toString
- Formatting many values → Intl.NumberFormat, reused
- Values you will parse back → never format first
- Exact decimal arithmetic → format at the end, compute in minor units
Notes
FAQ
They do the same work and take the same options. The method is convenient for a one-off; the constructor is much faster when formatting many values, because the locale data is prepared once instead of per call.
const f = new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}); rows.map(r => f.format(r.price));