PHP floor - Syntax
mixed floor(mixed n);
The floor() function in PHP is used to return the next lowest integer value (i.e. last largest integer not greaterthan the inputed value) by rounding up value if necessary.
mixed floor(mixed n);
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using floor math method and print the resultant in console.
<?php
class MathExample {
public function getfloorValue() {
echo("The floor value of 1.0 is " . floor(1.0) . "\n");
echo("The floor value of 1.1 is " . floor(1.1) . "\n");
echo("The floor value of 1.2 is " . floor(1.2) . "\n");
echo("The floor value of 1.3 is " . floor(1.3) . "\n");
echo("The floor value of 1.4 is " . floor(1.4) . "\n");
echo("The floor value of 1.5 is " . floor(1.5) . "\n");
echo("The floor value of 1.6 is " . floor(1.6) . "\n");
echo("The floor value of 1.7 is " . floor(1.7) . "\n");
echo("The floor value of 1.8 is " . floor(1.8) . "\n");
echo("The floor value of 1.9 is " . floor(1.9) . "\n");
echo("The floor value of 2.0 is " . floor(2.0) . "\n");
}
}
$obj = new MathExample();
$obj->getfloorValue();
Round the positive floating point number (random numbers) using floor math method and print the resultant in console.
<?php
class MathExample {
public function getfloorValue() {
echo("The floor value of 1.5698 is " . floor(1.5698) . "\n");
echo("The floor value of 1.3093 is " . floor(1.3093) . "\n");
echo("The floor value of 1.0087 is " . floor(1.0087) . "\n");
echo("The floor value of 1.1038 is " . floor(1.1038) . "\n");
echo("The floor value of 1.9573 is " . floor(1.9573) . "\n");
echo("The floor value of 1.7462 is " . floor(1.7462) . "\n");
echo("The floor value of 1.6427 is " . floor(1.6427) . "\n");
echo("The floor value of 1.4128 is " . floor(1.4128) . "\n");
echo("The floor value of 1.8099 is " . floor(1.8099) . "\n");
echo("The floor value of 1.2743 is " . floor(1.2743) . "\n");
echo("The floor value of 2.0001 is " . floor(2.0001) . "\n");
}
}
$obj = new MathExample();
$obj->getfloorValue();
Round the negative floating point number (random numbers) using floor math method and print the resultant in console.
<?php
class MathExample {
public function getfloorValue() {
echo("The floor value of -1.5698 is " . floor(-1.5698) . "\n");
echo("The floor value of -1.3093 is " . floor(-1.3093) . "\n");
echo("The floor value of -1.0087 is " . floor(-1.0087) . "\n");
echo("The floor value of -1.1038 is " . floor(-1.1038) . "\n");
echo("The floor value of -1.9573 is " . floor(-1.9573) . "\n");
echo("The floor value of -1.7462 is " . floor(-1.7462) . "\n");
echo("The floor value of -1.6427 is " . floor(-1.6427) . "\n");
echo("The floor value of -1.4128 is " . floor(-1.4128) . "\n");
echo("The floor value of -1.8099 is " . floor(-1.8099) . "\n");
echo("The floor value of -1.2743 is " . floor(-1.2743) . "\n");
echo("The floor value of -2.0001 is " . floor(-2.0001) . "\n");
}
}
$obj = new MathExample();
$obj->getfloorValue();
Round the infinity using floor math method and print the resultant in console.
<?php
class MathExample {
public function getfloorValue() {
// Positive ∞ infinite value
echo("The floor value of INF is " . floor(INF) . "\n");
// Negative ∞ infinite value
echo("The floor value of -INF is " . floor(-INF) . "\n");
}
}
$obj = new MathExample();
$obj->getfloorValue();