PHP floor() Function

Definition and Usage

The floor() function rounds down to the nearest integer.

Syntax

floor(x)
Parameter Description
x Required. A number.

Description

return a value not greater than x The next integer, will x The decimal part of the number is truncated to the nearest integer. The type returned by floor() is still float because the range of float values is usually larger than that of integer.

Example

In this example, we will apply the floor() function to different numbers:

<?php
echo(floor(0.60));
echo(floor(0.40));
echo(floor(5));
echo(floor(5.1));
echo(floor(-5.1));
echo(floor(-5.9))
?>

Output:

0
0
5
5
-6
-6