为什么当我使用 Intl.NumberFormat 格式化为欧元时,最后一位数字和 € 之间的空格与空格键不同?

gui*_*ord 1 javascript unicode whitespace currency euro

我想知道为什么欧元的货币格式化程序使用与按空格键时产生的正常空格不同的空格。这是一个代码示例,显示比较字符串变得复杂,特别是当我尝试对货币格式进行测试时。

\n

\r\n
\r\n
const number = 123456.789;\nlet curr = new Intl.NumberFormat(\'de-DE\', { style: \'currency\', currency: \'EUR\' }).format(number)\nconsole.log(curr); // expected output: "123.456,79 \xe2\x82\xac"\nconsole.log("123.456,79 \xe2\x82\xac" === curr) // Expected output: true -> but it outputs false!
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

epa*_*llo 5

它是一个不间断的空格%A0而不是%20. 这是有道理的,因为如果换行,您不希望您的行最终成为两行。