Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

floor

Rounds a number down to the nearest integer.

Available since: PHP 4

Syntax

floor(int|float $num): float

Parameters

ParameterTypeDescription
$numint|floatThe number to round.

Return value

floatThe largest integer not greater than `$num`.

Examples

Rounding down, including negative numbers:

<?php
 
echo floor(4.7), "\n";
echo floor(-4.7);

Output:

4
-5

The companion ceil() rounds up:

<?php
 
echo ceil(4.2), "\n";
echo ceil(-4.2);

Output:

5
-4

Notes

For negative numbers "down" means further from zero: floor(-4.7) gives -5. The result is a float.

See also

  • round — Rounds a number to a given number of digits.
  • intdiv — Performs integer division.

Related recipes

In the tutorial

  • Operators — Arithmetic, comparison and logical operators in PHP, and operator precedence.

Thanks for reading!

Donate to the site — we work hard for you.