比较时 toLocaleString 与字符串不一样

toLocalString not the same as string when comparing

我正在将两个字符串与似乎相同的货币进行比较。 一个是使用 toLocaleString() 创建的,另一个是通过声明静态字符串创建的。 两者在控制台上输出相同的值,但每种比较方法都对它们失败。

知道为什么这不起作用吗?这让我大吃一惊! 不知道是不是欧元符号...

const localStringValue = (2).toLocaleString('de', {style: 'currency', maximumFractionDigits: 2, currency: 'EUR'});
const stringValue = '2,00 €';

console.log('local string: ', localStringValue);
console.log('string: ', stringValue);

console.log('strict compare', localStringValue === stringValue);
console.log('compare', localStringValue == stringValue);
console.log('locale compare', localStringValue.localeCompare(stringValue));

价值和货币在localStringValue中被不间断space分隔,但在stringValue中是正常的space。

const localStringValue = (2).toLocaleString('de', {
  style: 'currency',
  maximumFractionDigits: 2,
  currency: 'EUR'
});
const stringValue = '2,00 €';

console.log('local string: ', localStringValue, encodeURIComponent(localStringValue));
console.log('      string: ', stringValue, encodeURIComponent(stringValue));