Thursday, June 28, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...