Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4428022
Votes 5
Synopsis System.out.println(0.001) outputs 0.0010
Category java:classes_lang
Reported Against 1.3 , 1.4.2 , merlin-rc1
Release Fixed 7(b75), 6-open(b17) (Bug ID:2181423)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 4154042 , 6899391 , 5078240
Submit Date 20-MAR-2001
Description


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) 
======================================================================




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)
======================================================================
  xxxxx@xxxxx   2004-11-11 21:41:23 GMT
Work Around
N/A
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.

  xxxxx@xxxxx   2001-03-20

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

  xxxxx@xxxxx   2002-05-28
Port fix from OpenJDK 6.
Posted Date : 2009-10-15 23:22:28.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang