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 Germande-CH "Swiss" Germande-DE Standard German (as spoken in Germany)el-GR Modern Greeken-AU Australian Englishen-CA Canadian Englishen-GB British Englishen-IE Irish Englishen-IN Indian Englishen-NZ New Zealand Englishen-US US Englishen-ZA English (South Africa)es-AR Argentine Spanishes-CL Chilean Spanishes-CO Colombian Spanishes-ES Castilian Spanish (as spoken in Central-Northern Spain)es-MX Mexican Spanishes-US American Spanishfi-FI Finnish (Finland)fr-BE Belgian Frenchfr-CA Canadian Frenchfr-CH "Swiss" Frenchfr-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" Italianit-IT Standard Italian (as spoken in Italy)ja-JP Japanese (Japan)ko-KR Korean (Republic of Korea)nl-BE Belgian Dutchnl-NL Standard Dutch (as spoken in The Netherlands)no-NO Norwegian (Norway)pl-PL Polish (Poland)pt-BR Brazilian Portuguesept-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 Tamilta-LK Sri Lankan Tamilth-TH Thai (Thailand)tr-TR Turkish (Turkey)zh-CN Mainland China, simplified characterszh-HK Hong Kong, traditional characterszh-TW Taiwan, traditional characters |
||||||||||||||||||||
options | Optional. An object with formatting options:
|
Return Value
Type | Description |
A string | A 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 |