ChoiceFormat previousDouble() method in Java with Examples

The previousDouble() method of java.text.ChoiceFormat class is used to get the double value just lesser than the passed double value.

Syntax:

public static final double previousDouble(double d)

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

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

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



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Lesser double value: 21.999999999999996

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// previousDouble() 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
        // lesser than the passed value
        // using previousDouble() method
        double value
            = ChoiceFormat.previousDouble(doub);
  
        // display the result
        System.out.println("Just lesser than "
                           + doub + ": "
                           + value);
    }
}

chevron_right


Output:

Just lesser than 1.23: 1.2299999999999998
Just lesser than 10.0: 9.999999999999998
Just lesser than -12.0: -12.000000000000002
Just lesser than 1.2000000476837158: 1.2000000476837156
Just lesser than 50.0: 49.99999999999999

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#previousDouble-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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.