Groovy Math.floor - Syntax
mixed floor(mixed n);
The Math.floor() function in Groovy 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.
import java.lang.Math;
class MathExample {
public static void main(String[] args) {
println("The floor value of 1.0 is " + Math.floor(1.0));
println("The floor value of 1.1 is " + Math.floor(1.1));
println("The floor value of 1.2 is " + Math.floor(1.2));
println("The floor value of 1.3 is " + Math.floor(1.3));
println("The floor value of 1.4 is " + Math.floor(1.4));
println("The floor value of 1.5 is " + Math.floor(1.5));
println("The floor value of 1.6 is " + Math.floor(1.6));
println("The floor value of 1.7 is " + Math.floor(1.7));
println("The floor value of 1.8 is " + Math.floor(1.8));
println("The floor value of 1.9 is " + Math.floor(1.9));
println("The floor value of 2.0 is " + Math.floor(2.0));
}
}
Round the positive floating point number (random numbers) using floor math method and print the resultant in console.
import java.lang.Math;
class MathExample {
public static void main(String[] args) {
println("The floor value of 1.5698 is " + Math.floor(1.5698));
println("The floor value of 1.3093 is " + Math.floor(1.3093));
println("The floor value of 1.0087 is " + Math.floor(1.0087));
println("The floor value of 1.1038 is " + Math.floor(1.1038));
println("The floor value of 1.9573 is " + Math.floor(1.9573));
println("The floor value of 1.7462 is " + Math.floor(1.7462));
println("The floor value of 1.6427 is " + Math.floor(1.6427));
println("The floor value of 1.4128 is " + Math.floor(1.4128));
println("The floor value of 1.8099 is " + Math.floor(1.8099));
println("The floor value of 1.2743 is " + Math.floor(1.2743));
println("The floor value of 2.0001 is " + Math.floor(2.0001));
}
}
Round the negative floating point number (random numbers) using floor math method and print the resultant in console.
import java.lang.Math;
class MathExample {
public static void main(String[] args) {
println("The floor value of -1.5698 is " + Math.floor(-1.5698));
println("The floor value of -1.3093 is " + Math.floor(-1.3093));
println("The floor value of -1.0087 is " + Math.floor(-1.0087));
println("The floor value of -1.1038 is " + Math.floor(-1.1038));
println("The floor value of -1.9573 is " + Math.floor(-1.9573));
println("The floor value of -1.7462 is " + Math.floor(-1.7462));
println("The floor value of -1.6427 is " + Math.floor(-1.6427));
println("The floor value of -1.4128 is " + Math.floor(-1.4128));
println("The floor value of -1.8099 is " + Math.floor(-1.8099));
println("The floor value of -1.2743 is " + Math.floor(-1.2743));
println("The floor value of -2.0001 is " + Math.floor(-2.0001));
}
}
Round the infinity using floor math method and print the resultant in console.
import java.lang.Math;
class MathExample {
public static void main(String[] args) {
println("The floor value of Infinity is " + Math.floor(Double.POSITIVE_INFINITY));
println("The floor value of -Infinity is " + Math.floor(Double.NEGATIVE_INFINITY));
}
}