Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: shocking imprecision

by rgiskard (Hermit)
on Oct 23, 2011 at 14:04 UTC ( #933209=note: print w/ replies, xml ) Need Help??


in reply to shocking imprecision

xrmb sprintf is the way to go, but if you're feeling lazy; just add "use bigrat;" (aka. big rational, cpan: bigrat) to the top of your proggie. It is not optimal (neither is bignum), but it does increases precision.

Example: imprecise.pl
use bigrat; print int(4.39 * 100) . "\n"; my $a = 4.39, $b = 100; print int ($a*$b) ."\n"; my $ans = $a*$b; print $a*$b ."\n"; print int ( $ans ) ."\n";
Output:
perl imprecise.pl 439 439 439 439


Comment on Re: shocking imprecision
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://933209]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-11-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls