Intl.NumberFormat 抛出错误“Uncaught RangeError:无效的货币代码”

vuv*_*uvu 3 javascript

我想编写一个格式函数来显示欧元价格,但它会引发错误。怎么了?

\n

\r\n
\r\n
const formatVal = val => new Intl.NumberFormat("de-DE", {\n  style: "currency",\n  currency: "\xe2\x82\xac"\n}).format(val)\n\nformatVal(456)
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

抛出的错误:

\n
\n

未捕获的 RangeError:无效的货币代码:\xc3\xa2\xc2\xac

\n
\n

Nao*_*dgi 7

将 \xe2\x82\xac 更改为 EUR

\n

\r\n
\r\n
const formatVal = val => new Intl.NumberFormat("de-DE", {\n  style: "currency",\n  currency: "EUR"\n}).format(val)\n\nconsole.log(formatVal(456))
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n