JavaScript Number.toLocaleString()Method
Example
Format a string using local settings:
let num1 = 1000000;
let text1 = num1.toLocaleString();
//Format a number as a string using a specific locale
let num2 = 1000000;
let text2 = num2.toLocaleString("fi-FI");
//Format a number as a currency string using a specific locale
//RMB
let num3 = 1000000;
let text3 = num3.toLocaleString("zh-CN", {style:"currency", currency:"CNY"});
//US Dollar
let num4 = 1000000;
let text4 = num4.toLocaleString("en-US", {style:"currency", currency:"USD"});
Try it Yourself »
Definition and Usage
The toLocaleString() method returns a string representation of a number in a specific locale.
The new locales and options parameters allow the application to specify the language to be formatted and customize the behavior of the function. In older implementations, the locales and options parameters are ignored, and the locale used and the form of the returned string depend entirely on the implementation.
Browser Support
Number.toLocaleString() is an ECMAScript3 (ES3) feature.
All browsers support ES3 (JavaScript 1999).
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes | Yes |
Supported in all latest browser versions(locales, options)Parameters:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | 11 | Yes | Yes | Yes | Yes |
Syntax
number.toLocaleString(locales, options)
Parameter Values
| Parameter | Description |
|---|---|
| locales | Optional. A formatting object, can be:ar-SA Arabic (Saudi Arabia)bn-BD Bengali (Bangladesh)bn-IN Bengali (India)cs-CZ Czech (Czech Republic)da-DK Danish (Denmark)de-AT Austrian Germande-CH "Swiss" Germande-DE Standard Germanel-GR Modern Greeken-AU Australian Englishen-CA Canadian Englishen-GB British Englishen-IE Irish Englishen-IN Indian Englishen-NZ New Zealand Englishen-US American Englishen-ZA English (South Africa)es-AR Argentine Spanishes-CL Chilean Spanishes-CO Colombian Spanishes-ES Castilian Spanish (used in north-central Spain)es-MX Mexican Spanishes-US Latin American Spanishfi-FI Finnish (Finland)fr-BE Belgian Frenchfr-CA Canadian Frenchfr-CH "Swiss" Frenchfr-FR Standard French (in France)he-IL Hebrew (Israel)hi-IN Hindi (India)hu-HU Hungarian (Hungary)id-ID Indonesian (Indonesia)it-CH "Swiss" Italianit-IT Standard Italian (used in Italy)ja-JP Japanese (Japan)ko-KR Korean (South Korea)nl-BE Belgian Dutchnl-NL Standard Dutchno-NO Norwegian (Norway)pl-PL Polish (Poland)pt-BR Brazilian Portuguesept-PT European Portuguesero-RO Romanian (Romania)ru-RU Russian (Russian Federation)sk-SK Slovak (Slovakia)sv-SE Swedish (Sweden)ta-IN Tamil (India)ta-LK Tamil (Sri Lanka)th-TH Thai (Thailand)tr-TR Turkish (Turkey)zh-CN Mainland China, Simplified Chinesezh-HK Hong Kong, Traditional Chinesezh-TW Taiwan, Traditional Chinese |
| options | Optional. Can be:
|
Return Value
| Type | Description |
|---|---|
| String | Returns a string representation in a locale. |
Technical Details
| JavaScript Version: | ECMAScript 6 |
|---|
More Examples
Example
Use optional parameters to format a currency string:
let num1 = new Number(1000000);
const myObj = {
style: "currency",
currency: "EUR"
}
let text1 = num1.toLocaleString("en-GB", myObj);
let num2 = new Number(1000000);
let text2 = num2.toLocaleString("en-GB", {style:"currency", currency:"EUR"});
//RMB
let num3 = 1000000;
let text3 = num3.toLocaleString("zh-CN", {style:"currency", currency:"CNY"});
//Japanese Yen
let num4 = 1000000;
let text4 = num4.toLocaleString("ja-JP", {style:"currency", currency:"JPY"});
Try it Yourself »
JavaScript Number Object