What can I do to prevent this kind of rounding error ?
Update: This is for the main part a rehash of what
haukex had posted 5 hours earlier ... something I had failed to observe first time round.
You could change the last line of your code from:
print "$_ => $x\n";to
printf "$_ => %.2f\n", $x;
Any module that does decimal (as opposed to binary) arithmetic would also provide correct results.
These modules include Math::BigFloat, Math::Decimal and Math::Decimal64.
Cheers,
Rob