The floor() function rounds a floating-point number to the nearest integer below its current value.
PHP floor() Function has the following syntax.
float floor ( float number )
Parameter | Is Required | Description |
---|---|---|
number | Required. | Value to round down |
If you provide an integer, nothing will happen.
Item | Value |
---|---|
Return Value | The value rounded down to the nearest integer |
Return Type | Float |
To round a number UP to the nearest integer, use ceil() function.
To round a floating-point number, use round() function.
<?PHP//from w w w. jav a 2s .c om
$number = floor(11.1); // 11
print $number;
print "\n";
$number = floor(11.9); // 11
print $number;
print "\n";
$number = floor(11); // 11
print $number;
print "\n";
echo(floor(0.60) . "\n");
echo(floor(0.40) . "\n");
echo(floor(5) . "\n");
echo(floor(5.1) . "\n");
echo(floor(-5.1) . "\n");
echo(floor(-5.9));
?>
For negative float value
floor()
rounds down, for example, floor(-3.5)
becomes -4.
The code above generates the following result.