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

Answer: How do I round a number?

by japhy (Canon)
on Jul 26, 2000 at 05:37 UTC ( #24383=categorized answer: print w/replies, xml ) Need Help??

Q&A > math > How do I round a number? - Answer contributed by japhy

Different rounding schema:
# 1.1 => 1; 1.9 => 1; -1.1 => -2; -1.9 => -2 $rounded = POSIX::floor($value); # 1.1 => 2; 1.9 => 2; -1.1 => -1; -1.9 => -1 $rounded = POSIX::ceil($value); # 1.1 => 1; 1.9 => 2; -1.1 => -1; -1.9 => -2 $rounded = round($value); sub round { $_[0] > 0 ? int($_[0] + .5) : -int(-$_[0] + .5) }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-02-25 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (367 votes). Check out past polls.