简体   繁体   English

格式化货币显示货币名称而不是符号

[英]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.

相关问题 两种货币的货币转换 - currency convertion with two currencies 使用Globalizejs库格式化货币时,如何删除货币符号? - How to remove currency symbol, when formatting currency using Globalizejs library? 使用不带货币符号的 Intl.NumberFormat 进行货币格式化 - Currency formatting using Intl.NumberFormat without currency symbol JavaScript将货币分为数字值和货币符号/名称 - JavaScript separate currency into number value and currency symbol/name 如何仅获取货币符号而无需从angularjs货币过滤器中格式化价格表达式 - How to retrieve only the currency symbol without formatting a price expression from angularjs currency filter 如何在角度js而不是默认值(美元$符号)中获取特定货币符号(在我的情况下为卢比符号) - How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol) 货币兑换在货币转换器中无法正常工作 - Change of currencies does not work correctly in the currency converter Javascript Regex 匹配多种货币符号和金额 - Javascript Regex to match multiple currencies symbol and amount intl.NumberFormat 显示 es-ES 货币格式的错误结果 - intl.NumberFormat shows incorrect result for es-ES currency formatting 如何在OXID eShop中获得货币名称而不是数字? - How to get currency name instead number in OXID eShop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM