Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!