javascriptunicodewhitespacecurrencyeuro

Why when I format with Intl.NumberFormat to euro, the whitespace between the last digit and the € is not the same as the spacebar?


I'm wondering why the currency formatter for euro uses a different whitespace than the normal space produced when pressing the spacebar. Here is a code example showing that comparing strings becomes complicated, specially when I try to do tests the for the currency format.

const number = 123456.789;
let curr = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number)
console.log(curr); // expected output: "123.456,79 €"
console.log("123.456,79 €" === curr) // Expected output: true -> but it outputs false!


Solution

  • It is a non breaking space %A0 instead of a %20. Makes sense since you would not want your line to end up on two lines if it wraps.