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

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

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 Report

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 Report

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