Java Math - floor() Method
The Java floor() method returns the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number. In special cases it returns the following:
- If the argument value is already an integer, then the result is the same as the argument.
- If the argument is NaN or infinity or positive zero or negative zero, then the result is the same as the argument.
Syntax
public static double floor(double arg)
Parameters
arg |
Specify a number. |
Return Value
Returns the next lowest integer value by rounding DOWN the specified number, if necessary.
Exception
NA.
Example:
In the example below, floor() method is used to round the fraction DOWN of the specified number.
public class MyClass { public static void main(String[] args) { System.out.println(Math.floor(10.5)); System.out.println(Math.floor(-10.5)); System.out.println(Math.floor(0.5)); System.out.println(Math.floor(-0.5)); } }
The output of the above code will be:
10.0 -11.0 0.0 -1.0
❮ Java Math Methods