Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: shocking imprecision

by rgiskard (Hermit)
on Oct 23, 2011 at 14:04 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found