Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Problems with number resolutionby syphilis (Archbishop) |
on Jan 01, 2018 at 23:19 UTC ( [id://1206522]=note: print w/replies, xml ) | 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"; 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
In Section
Seekers of Perl Wisdom
|
|