Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4428022

System.out.println(0.001) outputs 0.0010

XMLWordPrintable

    • b75
    • generic, x86
    • generic, linux, windows_2000, windows_xp

        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

              darcy Joe Darcy
              yyoungsunw Yung-ching Young (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: