寻找解决方案以获得包括便士在内的全部货币值(value)。 numberingSystem: 'fullwide'
获取完整数字时带有字母间距。是否有任何选项可以在 NumberFormat() 中获取带有货币代码的完整数字?
预期行为:€56.123456
const CurrencyFormat = (amount = 0, currency = 'eur', digitLength = 'latn') => {
return new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: currency,
numberingSystem: digitLength,
}).format(amount)
};
console.log(CurrencyFormat(56.123456, 'eur', 'fullwide'));
console.log(CurrencyFormat(56.123456));
最佳答案
将 maximumFractionDigits
属性添加到包含您要允许的小数位数的选项。
const CurrencyFormat = (amount = 0, currency = 'eur', digitLength = 'latn') => {
return new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: currency,
numberingSystem: digitLength,
maximumFractionDigits: 20,
}).format(amount)
};
console.log(CurrencyFormat(56.123456, 'eur', 'fullwide'));
console.log(CurrencyFormat(56.123456));
我通过找到单词 MaximumFractionDigits
in the specification 并发现它是 can be set through the options object. 实例的一个属性找到了这一点。
关于javascript - 如何在 NumberFormat 中获取小数点后的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70689727/