JavaScript Number toLocaleString()

Examples

Format a number into a string, using locale settings:

let num = 1000000;
let text = num.toLocaleString();
Try it Yourself »

Format a number into a string, using the locale specific of FINLAND:

let num = 1000000;
let text = num.toLocaleString("fi-FI");
Try it Yourself »

Format a number into a currency string, using the locale specific of USA:

let num = 1000000;
let text = num.toLocaleString("en-US", {style:"currency", currency:"USD"});
Try it Yourself »

More examples below


Description

The toLocaleString() returns a number as a string, using local language format.

The language format depends on the locale setup on your computer.


Syntax

number.toLocaleString(locales, options)

Parameters

Parameter Description
locales

Try it
Optional.
The language specific format to use.
Click on the "Try it" button to see all values in action.

ar-SA Arabic (Saudi Arabia)
bn-BD Bangla (Bangladesh)
bn-IN Bangla (India)
cs-CZ Czech (Czech Republic)
da-DK Danish (Denmark)
de-AT Austrian German
de-CH "Swiss" German
de-DE Standard German (as spoken in Germany)
el-GR Modern Greek
en-AU Australian English
en-CA Canadian English
en-GB British English
en-IE Irish English
en-IN Indian English
en-NZ New Zealand English
en-US US English
en-ZA English (South Africa)
es-AR Argentine Spanish
es-CL Chilean Spanish
es-CO Colombian Spanish
es-ES Castilian Spanish (as spoken in Central-Northern Spain)
es-MX Mexican Spanish
es-US American Spanish
fi-FI Finnish (Finland)
fr-BE Belgian French
fr-CA Canadian French
fr-CH "Swiss" French
fr-FR Standard French (especially in France)
he-IL Hebrew (Israel)
hi-IN Hindi (India)
hu-HU Hungarian (Hungary)
id-ID Indonesian (Indonesia)
it-CH "Swiss" Italian
it-IT Standard Italian (as spoken in Italy)
ja-JP Japanese (Japan)
ko-KR Korean (Republic of Korea)
nl-BE Belgian Dutch
nl-NL Standard Dutch (as spoken in The Netherlands)
no-NO Norwegian (Norway)
pl-PL Polish (Poland)
pt-BR Brazilian Portuguese
pt-PT European Portuguese (as written and spoken in Portugal)
ro-RO Romanian (Romania)
ru-RU Russian (Russian Federation)
sk-SK Slovak (Slovakia)
sv-SE Swedish (Sweden)
ta-IN Indian Tamil
ta-LK Sri Lankan Tamil
th-TH Thai (Thailand)
tr-TR Turkish (Turkey)
zh-CN Mainland China, simplified characters
zh-HK Hong Kong, traditional characters
zh-TW Taiwan, traditional characters

options Optional.
An object with formatting options:

currency Legal values: any currency code (like "EUR", "USD", "INR", etc.)
currencyDisplay
Legal values:
"symbol" (default)
"code"
"name"
localeMatcher
Legal values:
"best-fit" (default)
"lookup"
maximumFractionDigits
A number from 0 to 20 (default is 3)
maximumSignificantDigits
A number from 1 to 21 (default is 21)
minimumFractionDigits
A number from 0 to 20 (default is 3)
minimumIntegerDigits
A number from 1 to 21 (default is 1)
minimumSignificantDigits
A number from 1 to 21 (default is 21)
style
Legal values:
"currency"
"decimal" (default)
"percent"
useGrouping
Legal values:
"true" (default)
"false"

Return Value

Type Description
A stringA string representing a number the local format.


More Examples

Use the options parameter (object) for currency formatting:

let num = new Number(1000000);
const myObj = {
  style: "currency",
  currency: "EUR"
}
let text = num.toLocaleString("en-GB", myObj);
Try it Yourself »
let num = new Number(1000000);
let text = num.toLocaleString("en-GB", {style:"currency", currency:"EUR"});
Try it Yourself »

Using the locale specific of JAPAN:

let num = 1000000;
let text = num.toLocaleString("ja-JP", {style:"currency", currency:"JPY"});
Try it Yourself »

Browser Support

toLocaleString() is an ECMAScript3 (ES3) feature.

ES3 (JavaScript 1999) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Browser Support

(locales, options) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.