Thursday, December 18, 2025
HomeLanguagesPHP floor() Function

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.

  • 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

RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12036 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS