简体   繁体   English

Java:找不到符号

[英]Java: Can't find symbol

In Javadoc it was written that : 在Javadoc中写道:

public static String toString(double d) public static String toString(double d)

Returns a string representation of the double argument. 返回double参数的字符串表示形式。 All characters mentioned below are ASCII characters. 下面提到的所有字符都是ASCII字符。

If the argument is NaN, the result is the string "NaN". 如果参数是NaN,则结果是字符串“NaN”。

But when I am compiling below code it is giving error: Cant find symbol NaN 但是当我编译下面的代码时,它会给出错误:找不到符号NaN

String intStr2 =Double.toString(NaN); 

由于NaN未定义,因此会抛出编译错误,使用以下方法来克服同样的错误,

String intStr2 = Double.toString(Double.NaN);

Double.NaN is defined in Double.java as (ref jdk8) 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;

And it is well converted in String "NaN" 它在String“NaN”中转换得很好

String intStr2 =Double.toString(Double.NaN); 
System.out.println(intStr2);

The error NaN is "Not a Number". 错误NaN是“非数字”。 You'd have to define it first. 你必须先定义它。

String intStr2 = Double.toString(Double.NAN);

You'd be able to throw it in print and it should print. 你可以把它扔进去打印,它应该打印出来。 For infinity, you'd have to use(Positive and negative, interchangeable.) 对于无限,你必须使用(正面和负面,可互换。)

String intStr2 = Double.toString(Double.POSITIVE_INFINITY);
System.out.print(intStr2);

Should print out Infinity 应打印无限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM