我可以使用 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
我想要什么:
// 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
有没有办法让它始终显示货币类型指示符?我正在为语言环境和货币使用用户传递的变量。
最佳答案
听起来您想将 currencyDisplay: 'code'
添加到您的选项对象。
这不会为您提供您正在寻找的格式(100 美元,而不是 100 美元),但它应该始终让您的用户明确知道他们正在处理的货币类型,即使货币匹配语言环境。
关于javascript - JS toLocaleString 始终显示货币符号,无论语言环境如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37173558/