Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-19 02:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found