Skip to content
Related Articles

Related Articles

PHP floor() Function

View Discussion
Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 29 Jun, 2022
View Discussion
Improve Article
Save Article

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.

  • When a positive decimal number is passed.

PHP




<?php
    echo floor(2.8);
?>


Output:

2
  • When a negative decimal number is passed.

PHP




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


Output:

-4
  • When a number without decimal places is passed.

PHP




<?php
    echo floor(2);
?>


Output:

2

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!