Mor*_*gel 5 javascript localization currency internationalization
我可以根据区域设置格式化使用美元符号(比索、加元、澳元)的货币toLocaleString,但如果区域设置与货币匹配,则不会给出显示哪种货币的指示符。
我得到什么:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //$1,234.56
// US currency to AU locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'USD'}); //US$1,234.56
Run Code Online (Sandbox Code Playgroud)
我想要什么:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //US$1,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //A$1,234.56
Run Code Online (Sandbox Code Playgroud)
有没有办法让它始终显示货币类型指示器?我正在使用用户传递的区域设置和货币变量。
听起来您想添加currencyDisplay: 'code'到您的选项对象中。
这并不能准确地为您提供所需的格式(100 美元,而不是 100 美元),但它应该始终让您的用户明确知道他们正在处理的货币类型,即使货币与区域设置相匹配。
| 归档时间: |
|
| 查看次数: |
5717 次 |
| 最近记录: |