Skip to content
Related Articles

Related Articles

Improve Article

ChoiceFormat nextDouble(double) method in Java with Examples

  • Last Updated : 11 Aug, 2021

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:  

Java




// 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);
    }
}
Output: 
Next greater double value than 22: 22.000000000000004

 

Example 2: 



Java




// 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() method
        getValue(1.23d);
        getValue(10d);
        getValue(-12d);
        getValue(1.2f);
        getValue(50);
    }
 
    // defining getValue() method
    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);
    }
}
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 Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :