Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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?
[SwaJime]: couldn't find bitwise in precedence list for sybase
[SwaJime]: I bet that is why ... and that makes it to be I think terribly written code :-|

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2017-08-22 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (338 votes). Check out past polls.

    Notices?