1
parseFloat("-999999999999999.9991") returns -1000000000000000

and when debuging

(-1000000000000000 == -999999999999999.999) condition is true.

1 Answer 1

4

Operations with float data type have limited precision and they often introduce errors when rounding numbers like your case.

Sign up to request clarification or add additional context in comments.

2 Comments

how to make it return true like parseFloat("-999999999999999.9991") < -999999999999999.999
Well, in other programming languages you can use the decimal data type. In javascript there is no such data type, though and the solution is a little bit trickier. You can check the following links for a workaround of this problem: stackoverflow.com/questions/1458633/… or mredkj.com/javascript/nfbasic2.html. In general you should round your number to 2 or 3 signs after the decimal point before involving them in any operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.