代码之家  ›  专栏  ›  技术社区  ›  Sebastien Lorber

国际号码格式货币:$美国货币符号?

  •  0
  • Sebastien Lorber  · 技术社区  · 7 年前

    在法国我们从不使用 $US 那么为什么我会得到以下结果呢?

    new Intl.NumberFormat("fr-FR",{
                style: 'currency',
                currency: 'USD',
                minimumFractionDigits: 2,
             }).format("345")
    "345,00 $US"
    
    new Intl.NumberFormat("fr-FR",{
                style: 'currency',
                currency: 'EUR',
                minimumFractionDigits: 2,
             }).format("345")
    "345,00 €"
    

    另外:下面的内容对我来说也没有任何意义。我尝试了随机区域设置来查看影响,并得到了这2个不同的结果:

    new Intl.NumberFormat("en-HOS",{
                style: 'currency',
                currency: 'USD',
                minimumFractionDigits: 2,
             }).format("345")
    "345,00 $US"
    
    new Intl.NumberFormat("en-HOSSDDG",{
                style: 'currency',
                currency: 'USD',
                minimumFractionDigits: 2,
             }).format("345")
    "$345.00"
    

    0 回复  |  直到 7 年前
        1
  •  9
  •   John    5 年前

    在JS中格式化数字时,需要使用窄选项

    const amount = 123444;
    console.log(new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol'}).format(amount));
    

    看到了吗 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat 完整的细节。

        2
  •  0
  •   sebastien.prudhomme    6 年前

    v8javascript引擎正在使用i18N的ICU库。

    有关所有货币数据,请参见此处: https://github.com/unicode-org/icu/tree/master/icu4c/source/data/curr

    但法国人肯定用 美元