Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I’m confused

wrong calculating with floating point

$a = 601; foreach $b (0..9) { $c = $a + $b / 10; print "$c: " . (($c * 100) - ($c * 10 * 10)) . "\n"; }

601: 0
601.1: 0
601.2: 7.27595761418343e-12
601.3: -7.27595761418343e-12
601.4: 0
601.5: 0
601.6: 0
601.7: 7.27595761418343e-12
601.8: -7.27595761418343e-12
601.9: 0

Why?
1 person has
this problem
+1
Reply