floor(): Lowest nearest integer of a number

<?Php
echo floor(2.7).'<br>'; // Output 2
echo floor(2.4).'<br>'; // Output 2
echo floor(2.5).'<br>'; // Output 2
echo floor(-10.8).'<br>'; // Output -11
echo floor(-10.3).'<br>'; // Output -11
echo floor(-10.5).'<br>'; // Output -11
?>
floor() function returns the highest integer lower than the given number or the nearest integer ( on lower side ) of the number.


Here is a comparison between ceil(), floor() and round() function. For different input numbers we will get different values by using these functions.
ValueFloor()ceil()round()
2.7233
2.4232
2.5233
2.48232
2.62233
2222
-8.7-9-8-9
-8.5-9-8-9
-8.3-9-8-8
-8.49-9-8-8
-8.61-9-8-9
-8-8-8-8
Note that there is no point is using ceil() or floor() functions on integers directly. ( we will get the same value )

Example: Handling Negative Numbers

$num = -3.7;
echo floor($num);  // Output: -4

Example: Rounding Down Prices

$price = 19.99;
echo floor($price);  // Output: 19

Example: Comparing floor() and ceil()

$num = 4.3;
echo floor($num);  // Output: 4
echo ceil($num);   // Output: 5

Math Functions ceil Functions(Next higher integer) base_convert(): Convert number From any base to other
Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer