PHP floor() Function

In this chapter you will learn:

  1. Definition for PHP floor() Function
  2. Syntax for PHP floor() Function
  3. Parameter for PHP floor() Function
  4. Return for PHP floor() Function
  5. Note for PHP floor() Function
  6. Example - flooring a value

Definition

The floor() function rounds a floating-point number to the nearest integer below its current value.

Syntax

PHP floor() Function has the following syntax.

float floor ( float number )

Parameter

Parameter Is Required Description
numberRequired. Value to round down

If you provide an integer, nothing will happen.

Return

Item Value
Return Value The value rounded down to the nearest integer
Return Type Float

Note

To round a number UP to the nearest integer, use ceil() function.

To round a floating-point number, use round() function.

Example 1


<?PHP/*from  j  av  a 2 s . c om*/
$number = floor(11.1); // 11 
print $number;
print "\n";

$number = floor(11.9); // 11 
print $number;
print "\n";

$number = floor(11); // 11 
print $number;
print "\n";

echo(floor(0.60) . "\n");
echo(floor(0.40) . "\n");
echo(floor(5) . "\n");
echo(floor(5.1) . "\n");
echo(floor(-5.1) . "\n");
echo(floor(-5.9));
?>

For negative float value floor() rounds down, for example, floor(-3.5) becomes -4.

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP fmod() Function
  2. Syntax for PHP fmod() Function
  3. Parameter for PHP fmod() Function
  4. Return for PHP fmod() Function
  5. Example - Return the remainder of x/y