JavaScript Number.toLocaleString()Method

Number 对象参考手册JavaScript Number Object

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 German
de-CH "Swiss" German
de-DE Standard German
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 American English
en-ZA English (South Africa)
es-AR Argentine Spanish
es-CL Chilean Spanish
es-CO Colombian Spanish
es-ES Castilian Spanish (used in north-central Spain)
es-MX Mexican Spanish
es-US Latin American Spanish
fi-FI Finnish (Finland)
fr-BE Belgian French
fr-CA Canadian French
fr-CH "Swiss" French
fr-FR Standard French (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 (used in Italy)
ja-JP Japanese (Japan)
ko-KR Korean (South Korea)
nl-BE Belgian Dutch
nl-NL Standard Dutch
no-NO Norwegian (Norway)
pl-PL Polish (Poland)
pt-BR Brazilian Portuguese
pt-PT European Portuguese
ro-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 Chinese
zh-HK Hong Kong, Traditional Chinese
zh-TW Taiwan, Traditional Chinese

options Optional. Can be:
  • "decimal"Used for plain number formatting;
  • "currency"Used for currency formatting;
  • "percent"Used for percentage formatting;
  • "unit"Used for unit formatting

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 »

Number 对象参考手册JavaScript Number Object

Other Extensions