Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Number.prototype.toLocaleString

Formats a number by language rules: digit grouping, currency, percent.

Available since: ES3

Syntax

number.toLocaleString(locales, options)

Parameters

ParameterTypeDescription
localesstringOptional. The language and region, for example en-US or de-DE.
optionsobjectOptional. Settings: style, currency, minimumFractionDigits and others.

Return value

stringThe number formatted by the rules of the language.

Examples

Digit grouping in different languages:

const n = 1234567.891;
 
console.log(n.toLocaleString('en-US'));
console.log(n.toLocaleString('de-DE'));

Output:

1,234,567.891
1.234.567,891

Currency and percent:

console.log((1999.5).toLocaleString('en-US', { style: 'currency', currency: 'USD' }));
console.log((0.256).toLocaleString('en-US', { style: 'percent' }));

Output:

$1,999.50
26%

Notes

Without locales the user's browser language is used, so the result may differ between computers. To format many numbers it is faster to create one Intl.NumberFormat.

See also

Related recipes

In the tutorial

  • Formatting with Intl — Locale-aware formatting of numbers, money, dates and plural words in JavaScript: toLocaleString, Intl.NumberFormat, Intl.DateTimeFormat and Intl.PluralRules.

Thanks for reading!

Donate to the site — we work hard for you.