使用 JavaScript,什么是将点替换为逗号的正确方法(对于欧盟货币),例如:
2000.65
将是 2000,65
而不是 2,000.65
39.20
将是 39,20
我不确定 cost.replace('.', ',')
是否正确。有更好的选择吗?
最佳答案
您可以使用 Intl.NumberFormat
const n = 2000.65;
console.log(new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR'
}).format(n));
有some more options available ,比如是否显示千位分隔符,或是否显示 €
符号。下面将只显示欧洲符号的数字,没有千位分隔符。
const n = 2000.65;
console.log(new Intl.NumberFormat('de-DE', {
useGrouping: false,
}).format(n));
关于javascript - 货币 : Dot to Comma?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54744758/