View Full Version : ceil function?
toolkit
01-28-2003, 01:56 PM
I've been unable to find documentation on whether perl has a ceil function or not, so I have been using the function provided by the POSIX module.
Can anyone tell me if there is a native ceil function in perl, or give any code that could be used insead of the POSIX module?
Cheers!
Calilo
01-31-2003, 03:53 AM
I also looked for one but never found it, but i am quite happy using my posix one
just add the
use POSIX qw/ceil/;
$num = ceil($num);
Dont see why not using it, Posix already comes with perl.
Calilo
toolkit
01-31-2003, 09:20 AM
Thanks for the reply Calilo
If anyone wants a ceil function but doesn't want to/can't use the POSIX module, I've found this works the same:
sub ceil
# ceil() funtion to use instead of loading in
# the POSIX module each time
{
local ($amount) = @_;
$floor = int($amount);
$ceil = int($amount + 0.5);
if ($ceil == $floor)
{
$ceil++;
}
return $ceil;
}
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.