Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试打印一个小的双精度数字6.67e-11,但使用 Double.toString() 会返回0。我该怎么做才能让它打印 6.67e-11 (或类似的东西)呢?
6.67e-11
0
无法重现:
public class Test { public static void main(String args[]) { double d = 6.67e-11; System.out.println(Double.toString(d)); // Prints "6.67E-11" } }
IIRC,Double.toString()总是返回一个字符串,它允许使用Double.parseDouble().
Double.toString()
Double.parseDouble()
我的猜测是,由于其他操作中的一些舍入错误,您实际上并没有一个小的值 - 您有 0。