当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ChoiceFormat previousDouble()用法及代码示例


java.text.ChoiceFormat类的previousDouble()方法用于获取双精度值,该双精度值小于传递的双精度值。

用法:

public static final double previousDouble(double d)

参数:此方法接受双精度值d作为参数,并为其返回前一个双精度值。


返回值:此方法返回的double值比传递的double值小。

下面是说明previousDouble()方法的示例:

示例1:

// 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); 
    } 
}
输出:
Lesser double value: 21.999999999999996

示例2:

// 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); 
    } 
}
输出:
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

参考: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#previousDouble-double-



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 ChoiceFormat previousDouble() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。