Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript number.toLocaleString()显示某些语言的货币符号,其他语言的代码_Javascript - Fatal编程技术网

Javascript number.toLocaleString()显示某些语言的货币符号,其他语言的代码

Javascript number.toLocaleString()显示某些语言的货币符号,其他语言的代码,javascript,Javascript,我使用的是number.toLocaleString()函数,我的问题是,对于某些货币,它输出带有货币符号的价格,而对于其他货币,它输出货币代码 有些货币没有符号,但都有代码。我想将其正常化,并显示所有货币的代码 当前代码: const convertedPrice = Math.round(convertPrice(price, currency) * 10) / 10; const formattedPrice = convertedPrice.toLocaleString(coun

我使用的是number.toLocaleString()函数,我的问题是,对于某些货币,它输出带有货币符号的价格,而对于其他货币,它输出货币代码

有些货币没有符号,但都有代码。我想将其正常化,并显示所有货币的代码

当前代码:

  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"
  });