The ceil()
function rounds a floating-point number
to the nearest integer above its current value.
If you provide an integer, nothing will happen.
The ceil() function rounds a number UP to the nearest integer, if necessary.
PHP ceil() Function has the following format.
float ceil ( float num )
Parameter | Is Required | Description |
---|---|---|
number | Required. | Value to round up |
Item | Description |
---|---|
Return Value | The value rounded up to the nearest integer |
Return Type | Float |
To round a number DOWN to the nearest integer, look at the floor() function. To round a floating-point number, look at the round() function.
Round numbers up to the nearest integer:
<?php/*from w ww. j ava 2s . co m*/
$number = ceil(11.9); // 12
print($number);
print "\n";
$number = ceil(11.1); // 12
print($number);
print "\n";
$number = ceil(11); // 11
print($number);
print "\n";
echo(ceil(0.60) . "\n");
echo(ceil(0.40) . "\n");
echo(ceil(5) . "\n");
echo(ceil(5.1) . "\n");
echo(ceil(-5.1) . "\n");
echo(ceil(-5.9));
?>
The code above generates the following result.