Seb*_*ber 6 javascript currency number-formatting intl
我不明白 NumberFormat 是如何工作的。
在法国,我们从不使用$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 €"
Run Code Online (Sandbox Code Playgroud)
另外:以下对我来说也没有任何意义。我尝试了随机语言环境来查看影响并为这两个获得不同的结果:
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"
Run Code Online (Sandbox Code Playgroud)
这个 API 是坏的还是我错过了什么?
Joh*_*ohn 10
在 JS 中格式化数字时需要使用窄选项
“narrowSymbol” 使用窄格式符号(“$100”而不是“US$100”),
const amount = 123444;
console.log(new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol'}).format(amount));
Run Code Online (Sandbox Code Playgroud)
有关完整详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat。
小智 1
V8 JavaScript 引擎正在使用 i18N 的 ICU 库。
查看所有货币数据:https://github.com/unicode-org/icu/tree/master/icu4c/source/data/curr
但可以肯定的是,法国人在谈论美元时使用$而不是$US 。
| 归档时间: |
|
| 查看次数: |
7108 次 |
| 最近记录: |