PHP Function Reference

PHP floor() Function



The PHP floor() function returns the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number. In special cases it returns the following:

  • If the argument value is already an integer, then the result is the same as the argument.
  • If the argument is NAN or infinity, then the result is the same as the argument.

Syntax

floor(number)

Parameters

number Required. Specify a number.

Return Value

Returns the next lowest integer value by rounding DOWN the specified number, if necessary.

Example:

In the example below, floor() function is used to round the fraction DOWN of the specified number.

<?php
echo "floor(10.5) = ".floor(10.5)."\n";
echo "floor(-10.5) = ".floor(-10.5)."\n";
echo "floor(0.5) = ".floor(0.5)."\n";
echo "floor(-0.5) = ".floor(-0.5)."\n";
echo "floor(INF) = ".floor(INF)."\n";
echo "floor(-INF) = ".floor(-INF)."\n";
echo "floor(NAN) = ".floor(NAN)."\n";
?>

The output of the above code will be:

floor(10.5) = 10
floor(-10.5) = -11
floor(0.5) = 0
floor(-0.5) = -1
floor(INF) = INF
floor(-INF) = -INF
floor(NAN) = NAN

❮ PHP Math Reference