• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / PHP / php ceil – Round Up and Find the Ceiling of a Number in php

php ceil – Round Up and Find the Ceiling of a Number in php

December 20, 2021 Leave a Comment

To find the ceiling of a number using php, the easiest way is to use the php ceil() function.

echo ceil(2.434); // Output: 3

Finding the ceiling of a number in php is easy. We can round up numbers to the nearest integer with the php ceil() function.

echo ceil(5.4); // Output: 6

We can use the ceil() function to find the ceiling of both positive and negative numbers.

echo ceil(7.2); // Output: 8
echo ceil(-1.1); // Output: -1

If you pass an integer to the ceil() function, you will get that integer back.

echo ceil(9); // Output: 9

If you want to round down instead of rounding up, you can use the php floor() function.

Finding the Ceiling of Positive Number with ceil in php

Using the ceil() function, we can find the ceiling of positive numbers in php.

A few examples of calling the ceil() function with positive numbers are below:

echo ceil(1); // Output: 1
echo ceil(381.38); // Output: 382
echo ceil(100.123786); // Output: 101
echo ceil(9.9999); // Output: 10
echo ceil(9.0001); // Output: 10

Finding the Ceiling of Negative Number with ceil in php

Using the ceil() function, we can find the ceiling of negative numbers in php.

A few examples of calling the ceil() function with negative numbers are below:

echo ceil(-1); // Output: -1
echo ceil(-381.38); // Output: -381
echo ceil(-100.123786); // Output: -100
echo ceil(-9.9999); // Output: -9
echo ceil(-9.0001); // Output: -9

Hopefully this article has been helpful for you to use the php ceil() function to find the ceiling of a number.

Other Articles You'll Also Like:

  • 1.  Remove String from String in php with str_replace()
  • 2.  Truncate Strings in php Using substr()
  • 3.  What is the Difference Between unset() and unlink() in php?
  • 4.  php sin – Find Sine of Number in Radians Using php sin() Function
  • 5.  php unset – How to Destroy Variables in php
  • 6.  Check if Variable Exists in php with isset() Function
  • 7.  php Absolute Value with abs Function
  • 8.  Remove HTML Tags from String in php
  • 9.  php asinh – Find Hyperbolic Arcsine of Number Using php asinh() Function
  • 10.  php var_dump() Function – Print Information about Variable Type and Value

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy