floor() returns the next integer value downward. With negative numbers, that means moving toward the more negative integer.
echo floor(4.8); // 4
echo floor(-4.2); // -5
This is the recommended starting pattern. The detailed examples below are retained and modernized for additional variations and explanation.
<?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. | Value | Floor() | ceil() | round() |
|---|---|---|---|
| 2.7 | 2 | 3 | 3 |
| 2.4 | 2 | 3 | 2 |
| 2.5 | 2 | 3 | 3 |
| 2.48 | 2 | 3 | 2 |
| 2.62 | 2 | 3 | 3 |
| 2 | 2 | 2 | 2 |
| -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 |
$num = -3.7;
echo floor($num); // Output: -4
$price = 19.99;
echo floor($price); // Output: 19
$num = 4.3;
echo floor($num); // Output: 4
echo ceil($num); // Output: 5
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.