+ 2

Funny while loop output in playground

Why do i get more than one decimal in Ruby Code Playground? I have this while loop: x = 0 while x < 4 puts x x += 0.2 end and the output in playground: 0 0.2 0.4 0.6000000000000001 0.8 1.0 1.2 1.4 1.5999999999999999 1.7999999999999998 1.9999999999999998 2.1999999999999997 2.4 2.6 2.8000000000000003 3.0000000000000004 3.2000000000000006 3.400000000000001 3.600000000000001 3.800000000000001

5th Feb 2017, 5:55 PM
Barza Ditmar
Barza Ditmar - avatar
2 Respuestas
+ 10
Hahaha, I guess it's the playground error! Actually, it is not following the rules exactly as we specified!!!
17th Mar 2017, 10:01 AM
Harshit Gupta
Harshit Gupta - avatar
+ 6
Code Playground ftw xD
6th Feb 2017, 3:56 AM
Hatsy Rei
Hatsy Rei - avatar