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


Java ChoiceFormat nextDouble(double, boolean)用法及代码示例


如果传递的布尔值是true,则使用java.text.ChoiceFormat类的nextDouble(double,boolean)方法获取大于传递的double值的double值,否则,如果返回的double值小于传递的double值,则返回double值。传递的布尔值是false。

用法:

public static double nextDouble(double d, boolean positive)

参数:此方法接受以下参数如下


  • d:-它采用双精度值,其正值或大或小。
  • positive:-它使用布尔值,该布尔值检查返回的double值是否更大或更小。

返回值:如果传递的布尔值是true,则此方法返回的double值将大于传递的double值;如果传递的Boolean值为false,则此方法将返回的double值将小于传递的double值。

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

范例1:

// 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, false); 
  
        // display the result 
        System.out.print("Next Double value:"
                         + value); 
    } 
}
输出:
Next Double value:21.999999999999996

范例2:

// 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, true); 
        getValue(10d, false); 
        getValue(-12d, true); 
        getValue(1.2f, false); 
        getValue(50, true); 
    } 
  
    // defining getValue() mehtod 
    public static void getValue(double doub, 
                                boolean bool) 
    { 
  
        // getting double value just 
        // greater than the passed value 
        // using nextDouble() method 
        double value 
            = ChoiceFormat.nextDouble(doub, bool); 
  
        // display the result 
        if (bool) 
            System.out.println("Just greater than "
                               + doub + ":"
                               + value); 
        else
            System.out.println("Just lesser than "
                               + doub + ":"
                               + value); 
    } 
}
输出:
Just greater than 1.23:1.2300000000000002
Just lesser than 10.0:9.999999999999998
Just greater than -12.0:-11.999999999999998
Just lesser than 1.2000000476837158:1.2000000476837156
Just greater than 50.0:50.00000000000001

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



相关用法


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