Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Rounding to a Given Number of Significant Figures Rather Than Decimal Places

by aging acolyte (Pilgrim)
on Jan 13, 2003 at 14:03 UTC ( #226457=note: print w/ replies, xml ) Need Help??


in reply to Rounding to a Given Number of Significant Figures Rather Than Decimal Places

use the printf format. Where "%.2f" effectively means print to 2 decimal places - and perl rounds things nicely for you

my $number = 0.9999; printf "number = %.2f \n", $number;
Or if you just want to store it and then use it later uses sprintf
my $number = 0.9999; $rounded = sprintf "%.2f", $number; print "rounded = $number\n";

A.A.

Update:

A.A. is having a bad day and begs your indulgence for his stupidity


Comment on Re: Rounding to a Given Number of Significant Figures Rather Than Decimal Places
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-08-28 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls