in reply to for loop with float
The computer cannot accurately store 1/10 since it's a periodic number in binary (just like 1/3 is periodic in decimal).
>perl -e"printf '%.16e', 0.1" 1.0000000000000001e-001 ^ | |
Avoid the accumulation of error:
for (0..89) { my $i = $_ / 10; print "$i\n"; }
Update: and/or round your results.
|
|---|