Open In App

PHP floor() Function

We sometimes need to round down the float values to the next lowest integer in our maths problems. 

PHP provides a built-in function floor() to get this task done through our PHP script. The floor() function in PHP rounds down the float value to the next lowest integer value.

Syntax:

float floor(value)

Parameters: This function accepts the single parameter value which is rounded down to the next lowest integer. 

Return Value: The return type is a float value. It returns the next lowest integer value as a float which is rounded down, only if necessary.

Examples:

Input : floor(1.9)
Output : 1

Input : floor(-1.8)
Output : -2

Input : floor(4)
Output : 4

Note: floor() function is opposite to ceil() function in PHP

Below programs illustrate the floor() function in PHP.




<?php
    echo floor(2.8);
?>

Output:

2




<?php
    echo floor(-3.4);
?>

Output:

-4




<?php
    echo floor(2);
?>

Output:

2

Reference: https://www.php.net/manual/en/function.floor


Article Tags :