$input : Required : Input value in Integer or float
From a number we can find out the next higher integer using ceil function.
round() and ceil()
In case of round() function the value is rounded to higher or lower value, but here it is always higher value is returned.
Example
This function is useful when we search for a next higher hundred or thousand value of a number. For example we have a number 785 and wants to know what is the next higher hundredth number ( that is 800 ). To know this we can use ceil function. If you are generating a graph and coordinates are fixed according to high and low value of the data then using this function we can find out what should be our highest point in the graph.
$v=485;
$base_m=100;
$v_max=$base_m*(ceil($v/$base_m));
//$v_max equal to 500
Same way we can find out the nearest lower value of a number using floor function in php
$v=485;
$base_m=100;
$v_min=$base_m*(floor($v/$base_m));
//$v_min equal to 400
Here is a comparison between ceil(), floor() and round() function. For different input numbers we will get different values by using these functions.
Value
Floor()
ceil()
round()
3.7
3
4
4
3.4
3
4
3
3.5
3
4
4
3.48
3
4
3
3.62
3
4
4
2
2
2
2
-8.7
-9
-8
-9
-9.5
-10
-9
-10
-9.3
-10
-9
-9
-9.49
-10
-9
-9
-9.61
-10
-9
-10
-9
-9
-9
-9
Note that there is no point is using ceil or floor functions on integers directly. ( we will get the same value )
Example of uses of ceil function
Find out number of pages required to display 10 records per page.
While displaying fixed number of records per page and giving links to navigate to different pages ( known as pagination ) we can find out the number of pages by using ceil function. The number of pages will always have the closest integer value divisible by records per page which is higher than the number of records.
Example.
We are displaying 10 records per page.
If we have 41 records then we will have 5 pages and last page will show 1 record.
If we have 49 records then we will have 5 pages and last page will show 9 records.
If we have 50 records then we will have 5 pages and last page will show 10 records.