Java: 找不到符号
Java: Can't find symbol
在 Javadoc 中写道:
public static String toString(double d)
Returns a string representation of the double argument. All characters mentioned below are ASCII characters.
如果参数为 NaN,则结果为字符串“NaN”。
但是当我编译下面的代码时出现错误:找不到符号 NaN
String intStr2 =Double.toString(NaN);
由于没有定义NaN,所以会抛出编译错误,使用下面的方法来解决,
String intStr2 = Double.toString(Double.NaN);
Double.NaN
在 Double.java
中定义为 (ref 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 为 "Not a Number"。你必须先定义它。
String intStr2 = Double.toString(Double.NAN);
你可以把它打印出来,它应该打印出来。对于无穷大,你必须使用(正负,可互换。)
String intStr2 = Double.toString(Double.POSITIVE_INFINITY);
System.out.print(intStr2);
应该打印出 Infinity
在 Javadoc 中写道:
public static String toString(double d)
Returns a string representation of the double argument. All characters mentioned below are ASCII characters.
如果参数为 NaN,则结果为字符串“NaN”。
但是当我编译下面的代码时出现错误:找不到符号 NaN
String intStr2 =Double.toString(NaN);
由于没有定义NaN,所以会抛出编译错误,使用下面的方法来解决,
String intStr2 = Double.toString(Double.NaN);
Double.NaN
在 Double.java
中定义为 (ref 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 为 "Not a Number"。你必须先定义它。
String intStr2 = Double.toString(Double.NAN);
你可以把它打印出来,它应该打印出来。对于无穷大,你必须使用(正负,可互换。)
String intStr2 = Double.toString(Double.POSITIVE_INFINITY);
System.out.print(intStr2);
应该打印出 Infinity