JDK-4428022 : System.out.println(0.001) outputs 0.0010
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.0,1.4.0,1.4.2,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,linux,windows_2000,windows_xp generic,linux,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-03-20
  • Updated: 2009-10-24
  • Resolved: 2009-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b75Fixed OpenJDK6Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
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
PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk7/tl/jdk/rev/f85aa3aedf41
16-10-2009

EVALUATION Port fix from OpenJDK 6.
15-10-2009

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
28-07-2004

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
20-03-2001