JavaScript Number toLocaleString() 方法
定义和用法
toLocaleString() 方法使用本地语言格式将数字转换为字符串。
默认语言取决于计算机上的语言环境设置。
浏览器支持
直到 ECMAScript 5 和以下浏览器版本才支持参数区域设置和选项:
toLocaleString() | Yes | Yes | Yes | Yes | Yes |
locales | 24 | 11 | 29 | 10 | 15 |
options | 24 | 11 | 29 | 10 | 15 |
语法
number.toLocaleString(locales, options)
参数值
参数 | 描述 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
locales 测试一下 |
可选,使用哪种语言特定的格式。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 China, simplified characterszh-HK Hong Kong, traditional characterszh-TW Taiwan, traditional characters |
||||||||||||||||||||
options | 可选,你可以设置一些属性。
|
技术细节
返回值: | 表示数字的字符串 |
---|---|
JavaScript 版本: | ECMAScript 3 |
更多实例
实例
使用 options 参数将数字格式化为货币字符串:
var n = new Number(1000000);
var myObj = {
style: "currency",
currency: "EUR"
}
x = n.toLocaleString("en-GB", myObj);
亲自试一试 »