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

206
Vistas
Input type number is returning the value as string

Why is input type number returning the addition value as string but multiplication value in correct way? Any logic behind this, plz enlighten me

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

<input> tags always have a string value. That's just how it works. If you force the input to be a number field, then you will get a string of digits.

Why? Because this is what the HTML spec states will be the case. The the best answer I can give you.


I got the value from text box and multiplied it and it did it on correct way but when adding numbers like 55+10 it returns 5510 –

This is due to type coercion. This means that sometimes a string is converted to a number for you.

"55" + 10 // 5510

This happens because the + operator appends one string onto another.

"a" + "b" // "ab"

But when you multiply

"55" * 10 // 550

A string times a string doesn't make any sense, so it assumes you meant to do math and converts it to numbers for you.


When you want to do math from input fields you should convert it to a number first to ensure it does the right thing.

parseFloat("55") + 10 // 65
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