|Don't ask to ask, just ask|
Re: Problems with number resolutionby syphilis (Chancellor)
|on Jan 01, 2018 at 23:19 UTC||Need Help??|
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";
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.