(PHP 4, PHP 5, PHP 7, PHP 8)
ceil — Round fractions up
DescriptionReturns the next highest integer value by rounding up num
if necessary.
num
The value to round
num
rounded up to the next highest integer. The return value of ceil() is still of type float as the value range of float is usually bigger than that of int.
num
no longer accepts internal objects which support numeric conversion. Examples
Example #1 ceil() example
<?php
echo ceil(4.3), PHP_EOL; // 5
echo ceil(9.999), PHP_EOL; // 10
echo ceil(-3.14), PHP_EOL; // -3
?>
16 years ago
I needed this and couldn't find it so I thought someone else wouldn't have to look through a bunch of Google results-
<?phpif( !function_exists('ceiling') )
{
function ceiling($number, $significance = 1)
{
return ( is_numeric($number) && is_numeric($significance) ) ? (ceil($number/$significance)*$significance) : false;
}
}
echo
ceiling(0, 1000); echo ceiling(1, 1); echo ceiling(1001, 1000); echo ceiling(1.27, 0.05); ?>
eep2004 at ukr dot net ¶
6 years ago
Caution!
<?php
$value = 77.4;
echo ceil($value * 100) / 100; echo ceil(round($value * 100)) / 100;
20 years ago
I couldn't find any functions to do what ceiling does while still leaving I specified number of decimal places, so I wrote a couple functions myself. round_up is like ceil but allows you to specify a number of decimal places. round_out does the same, but rounds away from zero.
<?php
function round_up ($value, $places=0) {
if ($places < 0) { $places = 0; }
$mult = pow(10, $places);
return ceil($value * $mult) / $mult;
}function round_out ($value, $places=0) {
if ($places < 0) { $places = 0; }
$mult = pow(10, $places);
return ($value >= 0 ? ceil($value * $mult):floor($value * $mult)) / $mult;
}
echo
round_up (56.77001, 2); echo round_up (-0.453001, 4); echo round_out (56.77001, 2); echo round_out (-0.453001, 4); ?>
oktam ¶
14 years ago
Actual behaviour:
echo ceil(-0.1); //result "-0" but i expect "0"
Workaround:
echo ceil(-0.1)+0; //result "0"
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3