Possible Duplicate:
Is JavaScript’s Math broken?
In Javascript, I cannot figure out why 230/100*100 returns 229.99999999999997, while 240/100*100 returns 240.
This also applies to 460, 920 and so on…
Is there any solution?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In JavaScript all numeric values are stored as IEEE 754 64-bit floating-point values (also known as
doublein many languages). This representation has only finite precision (so not all numbers can be accurately represented) and it is binary, so values that seem to be easy to represent in decimal can turn out to be problematic to handle.There is no fire-and-forget solution suitable for everyone. If you need an integer then simply round using
Math.round.