问题描述
我正在从。以下代码演示了 Double.toString()
I am upgrading from JDK6 to JDK7. The following code demonstrate shows a minor change in Double.toString()
public class StringDemo
{
public static void main(String[] args)
{
System.out.println(Double.toString(.0005));
System.out.println(Double.toString(.005)); //different string
System.out.println(Double.toString(.05));
System.out.println(Double.toString(.5));
}
}
JRE6
5.0E-4
0.0050
0.05
0.5
JRE7
我正在寻找与上述变更相关的任何文件。兼容性页面不包括它。
I am looking for any documentation related to above change. The compatibility page does not cover it.
5.0E-4
0.005 //changed.
0.05
0.5
输出保存在许多参考文件中,并进行比较通过字符串比较 - 我需要修复比较,但很想知道有关此更改的更多详细信息。关于为什么这个改变会获得赏金的权威答案。
The output was saved in many reference files, and compared by string comparison- I need to fix the comparison, but curious to know more details about this change. Authoritative answer on why this change will get bounty.
推荐答案
这是Java 1.3到1.6中的一个错误(在1.7中解决)。
This was a bug in Java 1.3 through 1.6 (resolved in 1.7).
错误报告包含更多详细信息。已在JDK 7(b75)中修复。
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4511638The bug report http://bugs.sun.com/view_bug.do?bug_id=4428022 contains more details. Fixed in JDK 7 (b75).
相关报告 - 引用自上面的链接。
Related Reports- Quoted from the link above.
- Backport:JDK-2181423 - System.out.println(0.001)输出0.0010
- 重复:JDK-5078240 - Double.toString(double)添加尾随零
在某些情况下 - 重复:JDK-6575880 - Float.toString(float)添加尾随
zeros - 相关:JDK-6935102 - Regtest
关闭/ sun / misc / FloatingDecimal / ToString.java现在失败。 - 相关:JDK-4154042 - java.lang.FloatingDecimal可能是
淘汰
- Backport: JDK-2181423 - System.out.println(0.001) outputs 0.0010
- Duplicate: JDK-5078240 - Double.toString(double) adds a trailing zeroin certain cases
- Duplicate: JDK-6575880 - Float.toString(float) adds trailingzeros
- Relates: JDK-6935102 - Regtest
closed/sun/misc/FloatingDecimal/ToString.java now failing. - Relates: JDK-4154042 - java.lang.FloatingDecimal could beeliminated
OpenJDK 7修复此问题的更改位于:
The changes for OpenJDK 7 to fix this issue are available at: http://hg.openjdk.java.net/jdk7/tl/jdk/rev/f85aa3aedf41
这篇关于Java7 Double.toString()返回0.005 / java6,它是0.0050的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!