Java.lang Package Classes

Java Math - floor() Method



The java.lang.Math.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 a) 

Parameters

a 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 numbers.

import java.lang.*;

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.lang - Math

5