Java Tutorial Java Advanced Java References

Java Math - nextDown() Method



The Java nextDown() method returns the floating-point value adjacent to argument in the direction of negative infinity. In special cases it returns the following:

  • If either argument is a NaN, then NaN is returned.
  • If the argument is negative infinity, the result is negative infinity.
  • If the argument is zero, the result is -Double.MIN_VALUE or -Float.MIN_VALUE.

Syntax

public static double nextDown(double x)
public static float nextDown(float x)

Parameters

x Specify starting floating-point value.

Return Value

Returns the floating-point value adjacent to argument in the direction of negative infinity.

Exception

NA.

Example:

In the example below, nextDown() method returns the floating-point value adjacent to argument in the direction of negative infinity.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.nextDown(2.55)); 
  System.out.println(Math.nextDown(10.1));   
 }
}

The output of the above code will be:

2.5499999999999994
10.099999999999998

❮ Java Math Methods

5