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

156
Visualizações
Why parseInt 0.11 is not NaN but 0?

Is this normal?

newItemRowNumber
'0.11'
parseInt(newItemRowNumber)
0

I would expect that it is not parseable.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

parseInt parses the string for real numbers 0-9 at the start of the string. When it encounters a non integer character it stops parsing, in this case the .

19aaa becomes 19
0.11 becomes 0
11.111 becomes 11
abc11 becomes NaN
0xDEAD becomes 57005(Because of hexadecimal numbers)

about 4 years ago · Juan Pablo Isaza Relatório

0

From MDN:

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

0 is a numerial.

. is not.

So it takes the 0, ignores the ., ignores everything after the ., and you get 0.

about 4 years ago · Juan Pablo Isaza Relatório

0

This is normal because parseInt will just cut the fraction part from the given number string. And return the int value of the left side number of the dot. Here is Link parseInt() in JS.

As you are parsing float its better you can use parseFloat()

console.log(parseFloat("0.11"))
>>0.11
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