• 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 floor – Round Down and Find the Floor of a Number in php

php floor – Round Down and Find the Floor of a Number in php

December 20, 2021 Leave a Comment

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

echo floor(2.434); // Output: 2

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

echo floor(5.4); // Output: 5

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

echo floor(7.2); // Output: 7
echo floor(-1.1); // Output: -2

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

echo floor(9); // Output: 9

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

Finding the Floor of Positive Number with floor in php

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

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

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

Finding the Floor of Negative Number with floor in php

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

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

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

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

Other Articles You'll Also Like:

  • 1.  Using php to Copy Files Easily from One Directory to Another
  • 2.  php min – Find Minimum Value of Array in php
  • 3.  php Convert Radians to Degrees with php rad2deg() Function
  • 4.  Get Query String from URL in php
  • 5.  php sin – Find Sine of Number in Radians Using php sin() Function
  • 6.  php array_walk() – Modify Elements in Array with Callback Function
  • 7.  In PHP isset Method is Used For Checking if Variable is Defined
  • 8.  Creating Custom category.php With Pagination
  • 9.  php cos – Find Cosine of Number in Radians Using php cos() Function
  • 10.  Replace Underscore with Space in php 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