[英]Formatting currencies shows name of currency instead of symbol
I am using Number.prototype.toLocaleString()
like this我正在像这样使用
Number.prototype.toLocaleString()
5000.70.toLocaleString('en-AU', {
style: 'currency',
currency: 'EUR',
currencyDisplay: 'symbol',
useGrouping: true
}) // "EUR 5,000.70"
Expected outcome is either "5,000.70 €"
or "€5,000.70"
预期结果是
"5,000.70 €"
或"€5,000.70"
Instead the output in Chrome is "EUR 5,000.70"
相反,Chrome 中的 output 是
"EUR 5,000.70"
If you read up on the Intl.NumberFormat()
specification , the possible values of currencyDisplay
are:如果您阅读
Intl.NumberFormat()
规范, currencyDisplay
的可能值为:
symbol
" to use a localized currency symbol such as €, this is the default value, symbol
”使用本地化的货币符号,例如€,这是默认值,narrowSymbol
" to use a narrow format symbol ("$100" rather than "US$100"), narrowSymbol
”使用窄格式符号(“$100”而不是“US$100”),code
" to use the ISO currency code, code
”使用 ISO 货币代码,name
" to use a localized currency name such as " dollar
", name
”使用本地化的货币名称,例如“ dollar
”, So, it looks like it is a matter of setting currencyDisplay
to narrowSymbol
to achieve what you want:因此,看起来是将
currencyDisplay
设置为narrowSymbol
以实现您想要的问题:
const x = 5000.70.toLocaleString('en-AU', { style: 'currency', currency: 'EUR', currencyDisplay: 'narrowSymbol', useGrouping: true }); console.log(x); // €5,000.70
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.