Javascript number.toLocaleString()显示某些语言的货币符号,其他语言的代码
我使用的是number.toLocaleString()函数,我的问题是,对于某些货币,它输出带有货币符号的价格,而对于其他货币,它输出货币代码 有些货币没有符号,但都有代码。我想将其正常化,并显示所有货币的代码 当前代码:Javascript number.toLocaleString()显示某些语言的货币符号,其他语言的代码,javascript,Javascript,我使用的是number.toLocaleString()函数,我的问题是,对于某些货币,它输出带有货币符号的价格,而对于其他货币,它输出货币代码 有些货币没有符号,但都有代码。我想将其正常化,并显示所有货币的代码 当前代码: const convertedPrice = Math.round(convertPrice(price, currency) * 10) / 10; const formattedPrice = convertedPrice.toLocaleString(coun
const convertedPrice = Math.round(convertPrice(price, currency) * 10) / 10;
const formattedPrice = convertedPrice.toLocaleString(country, {
style: "currency",
currency: currency
});
当前输出(如果国家/地区为美国,货币为美元):$1.00
预期产出:1.00美元
当前和预期输出,如果国家/地区CZ,货币CZK:CZK 26.10
添加“货币显示”作为选项,并将其设置为“代码”
货币显示:“代码”添加“货币显示”作为选项,并将其设置为“代码”
currencyDisplay:“代码”使用选项
currencyDisplay:“代码”
const formattedPrice = convertedPrice.toLocaleString(country, {
style: "currency",
currency: "currency",
currencyDisplay: "code"
});
使用选项
当前显示:“code”
const formattedPrice = convertedPrice.toLocaleString(country, {
style: "currency",
currency: "currency",
currencyDisplay: "code"
});