The method floor provides the main integer that is less than or equivalent to the argument. floor() returns the twice value that is fewer than or equal to the argument and is equal to the adjacent mathematical integer. Note: If the argument is Integer, then the consequence is Integer. If the argument is NaN or an infinity or optimistic zero or negative zero, then the result is similar to the argument.
This method has the following variants:
double floor(double d) double floor(float f)
Here is the detail of parameters −
Example
public class Test { public static void main(String args[]) { double d = -100.675; float f = -90; System.out.println(Math.floor(d)); System.out.println(Math.floor(f)); System.out.println(Math.ceil(d)); System.out.println(Math.ceil(f)); } }
This will produce the following result:
-101.0 -90.0 -100.0 -90.0
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.