Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda