【问题标题】:intl.NumberFormat shows incorrect result for es-ES currency formattingintl.NumberFormat 显示 es-ES 货币格式的错误结果
【发布时间】:2019-11-22 09:38:45
【问题描述】:

我希望 es-ES 和 de-DE 语言环境的输出相同。 (我让我的西班牙同事查了他的工资单,他确认千后确实有小数)

var number = 1000;
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
console.log(new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR' }).format(number));

结果:

> "1.000,00 €"
> "1000,00 €"

【问题讨论】:

标签: javascript internationalization


【解决方案1】:

根据Real Academia Española,西班牙语的标准形式是将数字分成三个一组,用空格分隔,如果数字多于四位数字,即至少五个(来源:https://www.rae.es/dpd/números,第 2.a 节,西班牙语)。

实际上对于五位数的数字,您的代码为de-DEes-ES 给出了相同的结果,即用点分隔:

let number2 = 10000
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number2));
console.log(new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR' }).format(number2));

给我

10.000,00 €
10.000,00 €

用点分隔似乎并不完全正确*,但四位数字不进行分组似乎符合RAE的语言规则。

* 实际上,在德语中,根据 Duden 的说法,您应该使用空格而不是点,参见例如https://www.duden.de/sprachwissen/rechtschreibregeln/zahlen-und-ziffern(德语)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多