Thursday 28 June 2018

performance - Javascript avoid 0.2 + 0.4 = 0.6000000000000001 other than Math.round()

Is there any better way other than



Math.round(0.2+0.4) = 0.6


Actually, I have a series of index 0, 0.02, 0.04, 0.06, 0.08, 0.10 ----

I have to convert it to Array Index 0,1,2,3,4,5-- by dividing by 0.02



JavaScript provides



 0.28/0.02 = 14.000000000000002


I solve this problem by Math.round(0.28/0.02).
I am curious is there any other or better way to solve this problem

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...