Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ceil() function in PHP
The ceil() function rounds a number up to the nearest greater integer. This function always rounds up, regardless of the decimal value.
Syntax
ceil(number)
Parameters
number − The numeric value to round up
Return Value
Returns the value rounded up to the nearest integer as a float.
Example 1: Basic Usage
Here's how ceil() works with positive decimal numbers ?
<?php echo ceil(0.90) . "
"; echo ceil(0.15) . "
"; echo ceil(2.01) . "
"; ?>
1 1 3
Example 2: Whole Numbers
When applied to whole numbers, ceil() returns the same value ?
<?php echo ceil(2) . "
"; echo ceil(5) . "
"; ?>
2 5
Example 3: Negative Numbers
With negative numbers, ceil() rounds toward zero (less negative) ?
<?php echo ceil(8.9) . "
"; echo ceil(-9.2) . "
"; echo ceil(-3.1) . "
"; ?>
9 -9 -3
Key Points
Always rounds up to the next integer
Returns a float data type, not integer
For negative numbers, rounds toward zero (becomes less negative)
Whole numbers remain unchanged
Conclusion
The ceil() function is useful when you need the smallest integer greater than or equal to a given number, commonly used in pagination, quantity calculations, and mathematical operations requiring upward rounding.
