Friday, October 24, 2025
HomeLanguagesPHP ceil( ) Function

PHP ceil( ) Function

We have often used the ceiling function in mathematical problems to round up a decimal number to next greater integral value. PHP provides us with a built-in function ceil() to perform such operation. The ceil() function is a built-in function in PHP and is used to round a number to the nearest greater integer.

Syntax:  

float ceil(value)

Parameters: The ceil() function accepts a single parameter value which represents the number which you want to round up to the nearest greater integer.

Return Value: The return type of the ceil() function is float as shown in the syntax. It returns the number which represents the value rounded up to the next highest integer. 

Examples:  

Input : ceil(0.70)
Output : 1

Input : ceil(-4.1)
Output : -4

Input : ceil(6)
Output : 6

Below programs illustrate the ceil() function in PHP:  

  • When a positive number with decimal places is passed as a parameter:

PHP




<?php
  
echo (ceil(0.70));
  
?>      


Output: 

1
  • When a negative number with decimal places is passed as a parameter:

PHP




<?php
  
echo (ceil(-4.1));
  
?>


Output: 

-4
  • When a number with no decimal places is passed as a parameter:

PHP




<?php
  
echo (ceil(6));
  
?>


Output: 

6

Reference
http://php.net/manual/en/function.ceil.php
 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS