Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 musing on the Monastery: (7)
As of 2015-07-04 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls