Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 perusing the Monastery: (6)
As of 2015-07-29 04:29 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 (260 votes), past polls