JS toLocaleString 始终显示货币符号,无论语言环境如何
JS toLocaleString always show currency symbol regardless of locale
我可以使用 toLocaleString
根据语言环境设置使用美元符号(比索、加元、澳元)的货币的格式,但如果语言环境与货币匹配,则不会给出显示哪种货币的指示符。
我得到的:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //,234.56
// US currency to AU locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'USD'}); //US,234.56
我想要什么:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //US,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //A,234.56
有没有办法让它始终显示货币类型指示器?我正在为语言环境和货币使用用户传递的变量。
听起来您想将 currencyDisplay: 'code'
添加到您的选项对象中。
这不会为您提供您正在寻找的格式(100 美元,而不是 100 美元),但它应该始终让您的用户明确知道他们正在处理的货币类型,即使货币与语言环境匹配。
我可以使用 toLocaleString
根据语言环境设置使用美元符号(比索、加元、澳元)的货币的格式,但如果语言环境与货币匹配,则不会给出显示哪种货币的指示符。
我得到的:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //,234.56
// US currency to AU locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'USD'}); //US,234.56
我想要什么:
// US Currency to US Locale
(1234.56).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); //US,234.56
// AU Currency to AU Locale
(1234.56).toLocaleString('en-AU', {style: 'currency', currency: 'AUD'}); //A,234.56
有没有办法让它始终显示货币类型指示器?我正在为语言环境和货币使用用户传递的变量。
听起来您想将 currencyDisplay: 'code'
添加到您的选项对象中。
这不会为您提供您正在寻找的格式(100 美元,而不是 100 美元),但它应该始终让您的用户明确知道他们正在处理的货币类型,即使货币与语言环境匹配。