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

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

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