United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4428022 : System.out.println(0.001) outputs 0.0010

Details
Type:
Bug
Submit Date:
2001-03-20
Status:
Resolved
Updated Date:
2009-10-24
Project Name:
JDK
Resolved Date:
2009-10-24
Component:
core-libs
OS:
linux,generic,windows_xp,windows_2000
Sub-Component:
java.lang
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.0,1.4.0,1.4.2,6
Fixed Versions:

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Name: yyT116575			Date: 03/20/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

public class Dobble {
  public static void main( String[] args ) {
    System.out.println(0.001);
    System.out.println(0.001f);
    System.out.println(1.001);
    System.out.println(1.001f);
    System.out.println(0.1);
    System.out.println(0.1f);
    System.out.println(0.01);
    System.out.println(0.01f);
    System.out.println(0.0001);
    System.out.println(0.0001f);
  }
}

This gives an output of 0.0010 for actual value 0.001, which is inconsistent 
with other numbers (compare other lines output). 

This happens for all of 0.001, 0.002, ..., 0.009.

It occurs on jdk1.3 & jdk1.2.2 on windows and jdk1.2.2 on a sparc.
(Review ID: 119151) 
======================================================================

Name: rmT116609			Date: 02/11/2002


java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

DESCRIPTION OF THE PROBLEM :

---------- BEGIN SOURCE ----------
public class PrecisionTest {
	public static void main(String[] args) {
		System.out.println(Double.valueOf("0.003"));
	}
}
---------- END SOURCE ----------

System.out.println(Double.valueOf("0.003"));
Output will be 0.0030. I expect it to be 0.003.
(Review ID: 139078)
======================================================================
###@###.### 2004-11-11 21:41:23 GMT

                                    

Comments
EVALUATION

In general, it should not be expected that System.out.println(fp_literal) returns the same string as that which comprises fp_literal; in other words, println(0.1) _won't_ and shouldn't printout as "0.1".  Additionally, float and double version of (appearently) "the same" literal also in generaly won't print out as the same string.  However, trailing zeros should not be printed.

joe.darcy@eng 2001-03-20

Verified unncessary trailing zeros still printed; this should be corrected.

###@###.### 2002-05-28
                                     
2001-03-20
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
dragon


                                     
2004-07-28
EVALUATION

Port fix from OpenJDK 6.
                                     
2009-10-15
PUBLIC COMMENTS

See
http://hg.openjdk.java.net/jdk7/tl/jdk/rev/f85aa3aedf41
                                     
2009-10-16



Hardware and Software, Engineered to Work Together