ChoiceFormat nextDouble(double) method in Java with Examples

The nextDouble(double) method of java.text.ChoiceFormat class is used to get the double value just greater than the specified double value.

Syntax:

public static final double nextDouble(double d)

Parameter: This method accepts double value d as a parameter for which the next double value is returned.

Return Value: This method returns an double value just greater than the passed double value.

Below are the examples to illustrate the nextDouble() method:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// nextDouble() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // getting double value just
        // greater than the passed value
        // using nextDouble() method
        double value
            = ChoiceFormat.nextDouble(22);
  
        // display the result
        System.out.print("Next greater double"
                         + " value than 22: "
                         + value);
    }
}

chevron_right


Output:

Next greater double value than 22: 22.000000000000004

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// nextDouble() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // calling getValue() mehtod
        getValue(1.23d);
        getValue(10d);
        getValue(-12d);
        getValue(1.2f);
        getValue(50);
    }
  
    // defining getValue() mehtod
    public static void getValue(double doub)
    {
  
        // getting double value just
        // greater than the passed value
        // using nextDouble() method
        double value
            = ChoiceFormat.nextDouble(doub);
  
        // display the result
        System.out.println("Next greater double"
                         + " value than "
                         + doub + ": " + value);
    }
}

chevron_right


Output:

Next greater double value than 1.23: 1.2300000000000002
Next greater double value than 10.0: 10.000000000000002
Next greater double value than -12.0: -11.999999999999998
Next greater double value than 1.2000000476837158: 1.200000047683716
Next greater double value than 50.0: 50.00000000000001

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#nextDouble-double-

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Recommended Posts: