floor
Rounds a number down to the nearest integer.
Available since: PHP 4
Syntax
floor(int|float $num): floatParameters
| Parameter | Type | Description |
|---|---|---|
| $num | int|float | The number to round. |
Return value
floatThe largest integer not greater than `$num`.
Examples
Rounding down, including negative numbers:
<?php
echo floor(4.7), "\n";
echo floor(-4.7);Output:
4
-5The companion ceil() rounds up:
<?php
echo ceil(4.2), "\n";
echo ceil(-4.2);Output:
5
-4Notes
For negative numbers "down" means further from zero: floor(-4.7) gives -5. The result is a float.
See also
Related recipes
In the tutorial
- Operators — Arithmetic, comparison and logical operators in PHP, and operator precedence.