[英]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.