Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Answer: How do I round up a number?

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

Q&A > math > How do I round up a number? contributed by Anonymous Monk

Use the POSIX module:
use POSIX qw(ceil); print ceil(3.5); # prints 4 print ceil(4); # also prints 4
or, you can use this function:
sub roundup { my $n = shift; return(($n == int($n)) ? $n : int($n + 1)) }

Comment on Answer: How do I round up a number?
Select or Download Code
Replies are listed 'Best First'.
Re: Answer: How do I round up a number?
by I0 (Priest) on Mar 25, 2001 at 15:31 UTC
    roundup(-1.5) is wrong
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-11-29 19:05 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (752 votes), past polls