PHP Tutorial - PHP floor() Function






Definition

The floor() function rounds a floating-point number to the nearest integer below its current value.

Syntax

PHP floor() Function has the following syntax.

float floor ( float number )

Parameter

Parameter Is Required Description
numberRequired. Value to round down

If you provide an integer, nothing will happen.

Return

Item Value
Return Value The value rounded down to the nearest integer
Return Type Float




Note

To round a number UP to the nearest integer, use ceil() function.

To round a floating-point number, use round() function.

Example 1


<?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.