如何按货币名称将数字格式化为货币?
我有动态数字,只有货币名称(例如:美元,INR等)。我没有任何本地代码(比如,en-US)。
我会在下面试试这个。但它要求提供本地代码(“en-US”)。
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
formatter.format(2500)但我的数据库里没有“恩-美”。我只有货币名称和号码。
那么,如何根据货币名称将数字格式化为货币呢?
发布于 2020-06-16 05:02:52
把undefined传递给地区?
const getFormattedCurrency = (currency, amount) => new Intl.NumberFormat(undefined, {
style: 'currency',
currency,
}).format(amount);
console.log(getFormattedCurrency('USD', 2500));
console.log(getFormattedCurrency('JPY', 2500));
console.log(getFormattedCurrency('EUR', 2500));
console.log(getFormattedCurrency('CNY', 2500));
console.log(getFormattedCurrency('AUD', 2500));
console.log(getFormattedCurrency('INR', 2500));
https://stackoverflow.com/questions/62401187
复制相似问题