PHP ceil() Function

Learn via video courses
Topics Covered

The PHP ceil() function rounds the number to the nearest bigger integer, providing precision in calculations. It is particularly useful in financial scenarios where accurate, rounded-up values are essential. Let's discuss the syntax of the ceil() function in PHP.

Syntax of ceil() in PHP

The syntax of the ceil() function in PHP is as follows:

Parameter Values of ceil() in PHP

The only parameter accepted by the ceil() function is $number, which should be a float. This parameter represents the value that needs to be rounded up.

The parameter usage is as follows:

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Return Value of ceil() in PHP

The ceil() function returns the rounded-up value of the input number. It always returns a float, even if the input number itself is an integer. The returned value is the smallest integer greater than or equal to the input number. For example, ceil(4.3) will return 5.

PHP Version

Since its introduction in PHP 4.2.0, the ceil() function has been included as a standard part of the PHP language. It is compatible with all PHP versions, including PHP 5, PHP 7, and PHP`` 8.

PHP Changelog

Starting from PHP 4.2.0, the ceil() function has been accessible in all subsequent versions. No significant modifications or updates have been made to the ceil() function since its initial release.

Examples of ceil() in PHP

Here are some examples that show the application of the ceil() function in PHP

Example 1:

Sharpen Your Fundamentals with Free Learning

Output:

Explanation:

In this example, the value 2.34 is supplied to the ceil method. The ceil method converts it to the smallest integer greater than or equal to 2.34, which is 3 in this case. The result is displayed finally using the echo command.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example 2:

Output:

Explanation:

In this example, the value -2.34 is supplied to the ceil method. The ceil method converts it to the smallest integer greater than or equal to -2.34, which is -2 in this case. The result is displayed finally using the echo command.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example 3:

Output:

Explanation:

In this example, the value 10 is supplied to the ceil method. The ceil method converts it to the smallest integer greater than or equal to 10, which is 10 itself in this case. The result is displayed finally using the echo command.

Example 4:

Output:

Explanation:

In this example, the value -10 is supplied to the ceil method. The ceil method converts it to the smallest integer greater than or equal to -10, which is -10 itself in this case. The result is displayed finally using the echo command.

Conclusion

  • The ceil() function in PHP is a valuable tool for precise rounding up of numbers.
  • It finds applications in various scenarios such as financial applications, statistical calculations, and other projects where accurate rounding is necessary.
  • Understanding the syntax, parameter values, return value, and compatibility of the ceil() function allows us to effectively incorporate it into our PHP projects.
  • Since its introduction in PHP 4.2.0, no significant changes or updates have been made to the ceil() function.
  • By utilizing the ceil() function, developers can enhance the accuracy and reliability of their applications, ensuring that calculations meet specific rounding requirements.
  • It provides greater control over rounding decimal numbers to the nearest integer, making it a valuable asset in a developer's toolkit for handling precision rounding.