in reply to Decimal Increment Bug?
1/10 is a periodic number in binary, just like 1/3 is a periodic number in decimal. As such, it can't be accurately stored as a floating-point number.
First, reduce the accumulation of error through the use of integers.
Secondly, use rounding or a tolerance when appropriate.
for my $i (0..89) { my $v = $i / 10; printf "%.1f\n", $v; }
(Because we avoided the accumulation of error, the rounding isn't actually needed here.)
|
|---|