Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
toLocalString not the same as string when comparing

I am comparing two strings with a currency that seems to be the same. One is created with toLocaleString() and the other by declaring a static string. Both put out the same value on the console, but every compare method fails for them.

Any idea why this is not working? This is blowing my mind! I am not sure if it is the euro symbol...

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Value and currency is separated by non-breaking space in localStringValue, but in stringValue it's normal 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));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!