Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How do I round a number?

( #24383=categorized answer: print w/ replies, xml ) Need Help??

Q&A > math > How do I round a number? 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) }

Comment on Answer: How do I round a number?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-09-22 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls