To find the ceiling of a number using php, the easiest way is to use the php ceil() function.

echo ceil(2.434); // Output: 3

Finding the ceiling of a number in php is easy. We can round up numbers to the nearest integer with the php ceil() function.

echo ceil(5.4); // Output: 6

We can use the ceil() function to find the ceiling of both positive and negative numbers.

echo ceil(7.2); // Output: 8
echo ceil(-1.1); // Output: -1

If you pass an integer to the ceil() function, you will get that integer back.

echo ceil(9); // Output: 9

If you want to round down instead of rounding up, you can use the php floor() function.

Finding the Ceiling of Positive Number with ceil in php

Using the ceil() function, we can find the ceiling of positive numbers in php.

A few examples of calling the ceil() function with positive numbers are below:

echo ceil(1); // Output: 1
echo ceil(381.38); // Output: 382
echo ceil(100.123786); // Output: 101
echo ceil(9.9999); // Output: 10
echo ceil(9.0001); // Output: 10

Finding the Ceiling of Negative Number with ceil in php

Using the ceil() function, we can find the ceiling of negative numbers in php.

A few examples of calling the ceil() function with negative numbers are below:

echo ceil(-1); // Output: -1
echo ceil(-381.38); // Output: -381
echo ceil(-100.123786); // Output: -100
echo ceil(-9.9999); // Output: -9
echo ceil(-9.0001); // Output: -9

Hopefully this article has been helpful for you to use the php ceil() function to find the ceiling of a number.

Categorized in:

PHP,

Last Update: February 26, 2024