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

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • 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.  php switch case – How to Use Switch…Case Statements in php
  • 2.  php str_replace – Replace String in php
  • 3.  Check if Variable Exists in php with isset() Function
  • 4.  php e – Using M_E and exp() Function to Get Euler’s Constant e
  • 5.  How to Get Current System IP Address in php
  • 6.  php cosh – Find Hyperbolic Cosine of Number Using php cosh() Function
  • 7.  Get Word Count of String in php with str_word_count() Function
  • 8.  php array_merge() – Merge One or More Arrays Together by Appending
  • 9.  php array_pop() – Remove Last Element from Array
  • 10.  php preg_match_all – Get All Matches of Pattern in String

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