CKTIS / PHP
floor()
Use floor to round toward negative infinity, returning the greatest integral value no larger than the input as a float.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
floor(int|float $num): floatUse floor to round toward negative infinity, returning the greatest integral value no larger than the input as a float. For a negative fraction this moves away from zero, unlike an integer cast. Binary floating-point approximations just below an integer can lower the result by one. Only int values exactly representable as float retain their value. On 64-bit systems 9007199254740993 becomes 9007199254740992.
Signature
floor(int|float $num): float
Example output
[-3,-2,"float"]
[2,2,"float"]
[3,3,"float"]
[0,0,"float"]
9007199254740992
Examples
<?php
foreach ([-2.1, 2.9, 3, 0.9999999999999999] as $x) {
$r = floor($x);
echo json_encode([$r, (int)$x, get_debug_type($r)]), PHP_EOL;
}
if (PHP_INT_SIZE === 8) { printf("%.0f", floor(9007199254740993)); }
Result
[-3,-2,"float"] [2,2,"float"] [3,3,"float"] [0,0,"float"] 9007199254740992