[英]Java: Can't find symbol
在Javadoc中寫道:
public static String toString(double d)
返回double參數的字符串表示形式。 下面提到的所有字符都是ASCII字符。
如果參數是NaN,則結果是字符串“NaN”。
但是當我編譯下面的代碼時,它會給出錯誤:找不到符號NaN
String intStr2 =Double.toString(NaN);
由於NaN未定義,因此會拋出編譯錯誤,使用以下方法來克服同樣的錯誤,
String intStr2 = Double.toString(Double.NaN);
Double.NaN
中定義Double.java
如(參考文獻jdk8)
/**
* A constant holding a Not-a-Number (NaN) value of type
* {@code double}. It is equivalent to the value returned by
* {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
*/
public static final double NaN = 0.0d / 0.0;
它在String“NaN”中轉換得很好
String intStr2 =Double.toString(Double.NaN);
System.out.println(intStr2);
錯誤NaN是“非數字”。 你必須先定義它。
String intStr2 = Double.toString(Double.NAN);
你可以把它扔進去打印,它應該打印出來。 對於無限,你必須使用(正面和負面,可互換。)
String intStr2 = Double.toString(Double.POSITIVE_INFINITY);
System.out.print(intStr2);
應打印無限
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.