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//www .  j a v a  2 s  .c  o m
$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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions