• 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
  • Ruby
  • 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.  Add Months to Date in php
  • 2.  How to Reverse Array in php Without a Function or Other Variables
  • 3.  Get Array Length with php count() Function
  • 4.  Delete Cookie Using php
  • 5.  Check if String Ends with Given String in php with str_ends_with()
  • 6.  echo php – Output One or More Strings
  • 7.  Replace Underscore with Space in php String
  • 8.  Using strtolower() in php to Convert String to Lowercase
  • 9.  php session_destroy() – Delete Session File Where Session Data is Stored
  • 10.  In PHP isset Method is Used For Checking if Variable is Defined

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

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

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 © 2023 · The Programming Expert · About · Privacy Policy