我正在尝试用Intl.NumberFormat.格式化一个数字
我已经检查了MDN WebDocs,但是我无法得到响应,我想它应该会返回。
我正在用西班牙语的语言环境格式化,我想要获得数千之间的点分隔符(使用useGrouping选项),但是,我没有得到它
var sNumber = '1124.5'
var number = new Number(sNumber);
let style = {
style: 'currency',
currency: "EUR",
minimumFractionDigits: 2,
useGrouping: true
};
const formatter = new Intl.NumberFormat("es", style);
console.log(formatter.format(number));
发布于 2019-10-17 10:43:28
这似乎是西班牙格式化程序的一个特点,包括4位数字数字(即1234.56)。
看一看下面的内容并运行它:
let style = {
style: 'currency',
currency: "EUR",
minimumFractionDigits: 2,
useGrouping: true
};
var formatter = new Intl.NumberFormat("es", style);
console.log('Spanish (ES)');
console.log(formatter.format(1234.56));
console.log(formatter.format(12345.67));
console.log(formatter.format(123456.78));
formatter = new Intl.NumberFormat("de-DE", style);
console.log('German (de-DE)');
console.log(formatter.format(1234.56));
console.log(formatter.format(12345.67));
console.log(formatter.format(123456.78));
您将看到,对于5位及以上的数字,西班牙格式化程序确实按预期对数字进行分组。
但是,如果使用德语格式化程序(de-DE),它将正确格式化4位数字.
输出:
Spanish (ES)
1234,56 €
12.345,67 €
123.456,78 €
German (de-DE)
1.234,56 €
12.345,67 €
123.456,78 €https://stackoverflow.com/questions/58430460
复制相似问题