Java7 Double.toString() returns 0.005 / java6 it is 0.0050

前端 未结 1 507
独厮守ぢ
独厮守ぢ 2020-12-29 23:45

I am upgrading from JDK6 to JDK7. The following code demonstrate shows a minor change in Double.toString()

public class StringDemo
{

    pu         


        
相关标签:
1条回答
  • 2020-12-30 00:02

    This was a bug in Java 1.3 through 1.6 (resolved in 1.7).

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4511638 The 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) outputs 0.0010
    • Duplicate: JDK-5078240 - Double.toString(double) adds a trailing zero in certain cases
    • Duplicate: JDK-6575880 - Float.toString(float) adds trailing zeros
    • Relates: JDK-6935102 - Regtest
      closed/sun/misc/FloatingDecimal/ToString.java now failing.
    • Relates: JDK-4154042 - java.lang.FloatingDecimal could be eliminated

    The changes for OpenJDK 7 to fix this issue are available at: http://hg.openjdk.java.net/jdk7/tl/jdk/rev/f85aa3aedf41

    0 讨论(0)
提交回复
热议问题