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

The java.sql.Numeric(double d, int scale) constructor works wrong

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P1
    • None
    • 1.0.2
    • core-libs
    • sparc
    • solaris_2.5

    Description



      Name: saf@russia Date: 09/04/96


      This bug was found by St.Petersburg Java SQE team (by Mikhail Gorshenev).

      The java.sql.Numeric(double d, int scale) constructor works wrong.
      Value looses precision.

      The java.sql specification (JDBC version 1.01) says the following:
      " public Numeric(double x, int scale)
            Construct a Numeric from a double given a double value and an
            integer scale. The scale is set to the value specified.
            No implicit decimal point is assumed, i.e., if the double value is
            "1234" and the scale 2, the resulting numeric will be "1234.00.
            If the double value is "1234.5" and the scale 2 the value will
            be "1234.50". Rounding may occur during this conversion.
            Parameters:
                  x - The double value used to initialize the new Numeric.
                  scale - The desired number of digits after the decimal point.
      "


      Here is the minimized test demonstrating the bug:

      ----- java_sql_Numeric_Ctor2.java ---------------------------------------
      import java.sql.Numeric;
      class java_sql_Numeric_Ctor2 {
        public static void main(String argv[]) {
            Numeric n = new Numeric(1234.56789,10);
                   // will print "1234.5700000000" instead of "1234.5678900000"
            System.out.println("Numeric(1234.56789,10) = " + n);
        }
      }

      ----- The output of the test: -------------------------
      Numeric(1234.56789,10) = 1234.5700000000
      -------------------------------------------------------


      Workaround:
      None
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              mhapnersunw Mark Hapner (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: