2

This is a very strange javascript behaviour, anyone can explain that ?

for(var i=0; i < 0.2 ; i += 0.05)
   {
    console.log(i);
   }

Return in console :

0 
0.05 
0.1 
0.15000000000000002 

0.15000000000000002 ?

What is this ?

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Samsy
  • 365
  • 1
  • 2
  • 12

1 Answers1

1

You should read about floating point numbers. http://en.wikipedia.org/wiki/Floating_point

Also, there are some nice answers here: How to deal with floating point number precision in JavaScript?

Community
  • 1
  • 1
Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43