java.text.ChoiceFormat類的nextDouble(double)方法用於獲取恰好大於指定的double值的double值。
用法:
public static final double nextDouble(double d)
參數:此方法接受雙精度值d作為參數,為其返回下一個雙精度值。
返回值:此方法返回一個雙精度值,該值剛大於傳遞的雙精度值。
下麵是說明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);
// display the result
System.out.print("Next greater double"
+ " value than 22: "
+ value);
}
}
輸出:
Next greater double value than 22: 22.000000000000004
示例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);
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);
}
}
輸出:
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
參考: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#nextDouble-double-
相關用法
- Java ChoiceFormat format()用法及代碼示例
- Java ChoiceFormat hashCode()用法及代碼示例
- Java ChoiceFormat getFormats()用法及代碼示例
- Java ChoiceFormat previousDouble()用法及代碼示例
- Java ChoiceFormat parse()用法及代碼示例
- Java ChoiceFormat setChoices()用法及代碼示例
- Java ChoiceFormat getLimits()用法及代碼示例
- Java ChoiceFormat equals()用法及代碼示例
- Java ChoiceFormat applyPattern()用法及代碼示例
- Java ChoiceFormat nextDouble(double, boolean)用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ChoiceFormat nextDouble(double) method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。