
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP ceil() Function
Definition and Usage
The ceil() function is an in-built function in PHP iterpreter. This function accepts any float number as argument and rounds it up to the next highest integer.
This function always returns a float number as range of float is bigger than that of integer.
Syntax
ceil ( float $num ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
num The number to be rounded up. |
Return Values
PHP ceil() function returns the smallest integer value that is bigger than or equal to given parameter.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example rounds 5.78 to its next highest integer which is 6
<?php $arg=5.78; $val=ceil($arg); echo "ceil(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
ceil(5.78) = 6
Example
Following example shows that next highest integer to 15.05 is 16.−
<?php $arg=15.05; $val=ceil($arg); echo "ceil(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
ceil(15.05) = 16
Example
The ceil() function returns 0 for a string parameter −
<?php $arg="Hello"; $val=ceil($arg); echo "ceil(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
ceil(Hello) = 0
Example
For negative number, it is rounded towards 0 −
<?php $arg=-3.95; $val=ceil($arg); echo "ceil(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
ceil(-3.95) = -3