Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Answer: How do I round a number?

by I0 (Priest)
on Dec 16, 2000 at 02:38 UTC ( #46952=note: print w/ replies, xml ) Need Help??


in reply to Answer: How do I round a number?
in thread math

$rounded = int ( $orig + 0.5 ) assumes $rounded is positive.
More generally:  use POSIX; $rounded = floor ( $orig + 0.5 )
or $rounded = sprintf( "%.f" , $orig ) to properly handle the half-way case
See also `perldoc -q round`


Comment on Re: Answer: How do I round a number?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-11-26 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (165 votes), past polls