Java Math.floor() Method with Examples

Finding the floor value (rounded down value) for some given number (Java Math floor method)

Another method is the floor, which rounds down the number. This means that if the number is 17.34, the floor value of this number is going to be 17.0. Even if the number is 17.99, its floor value is going to be 17.0. Have a look at the below program –

import java.lang.Math;
public class UnderstandingMath {
public static void main(String[] args) {
System.out.println(Math.floor(17.99));
}
}

The output of this program is 17.0, which is the floor value of the given double value of 17.99.

Special cases –

  • If the argument is already equal to a mathematical integer, then the output is the same as the argument.
  • If the argument is NaN, or positive or negative infinity, or zero(positive or negative), the output is the same as the argument.