PHP ceil() Function

Definition and Usage

The ceil() function rounds up to the nearest integer.

Syntax

ceil(x)
Parameter Description
x Required. A number.

Description

returns not less than x to the next integer,x If there is a fractional part, it will be rounded up. The type returned by ceil() is still float because the range of float values is usually larger than that of integer.

Example

In this example, we will apply the ceil() function to different values:

<?php
echo(ceil(0.60);
echo(ceil(0.40);
echo(ceil(5);
echo(ceil(5.1);
echo(ceil(-5.1);
echo(ceil(-5.9));
?>

Output:

1
1
5
6
-5
-5