Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda