3 Replies Latest reply on May 26, 2003 5:30 AM by rgucci

    double bean member getting rounded in sybase?

    jamesduplain

      Hi,

      I have a CMP bean that has a member that is a primitive double (JB2.4.3). I am using Sybase 7 with the field mapped to a DOUBLE PRECISION column.

      The field is getting rounded when it gets put in the DB.
      For example: when I set the field to 4.5, it ends up in the DB as 4.499999999981.

      Any ideas on how to make it actually put 4.50000 in there?

      Thanks

        • 1. Re: double bean member getting rounded in sybase?
          jamesduplain

          Just tried it with a Double instead of double and had the same problem.

          • 2. Re: double bean member getting rounded in sybase?
            davidjencks

            Floating point numbers are not exact numerics. I suspect a double 4.5 == 4.49999... in java itself. It certainly cant't be represented exactly. If you want exact decimal calculations use Numeric(x, y) in your db and BigDecimal in java. With luck, your db driver might support this. You can also use int or long and scale it yourself.

            • 3. Re: double bean member getting rounded in sybase?
              rgucci

              We are having a problem with inserting values into a NUMERIC field in Sybase using CMP.

              The entity bean's field is defined as BigDecimal.
              The Sybase table field is defined as NUMERIC(18,4).

              In jaws.xml, a type mapping is defined for the bigdecimal field as

              <cmp-field>
              <field-name>homeAmt</field-name>
              <column-name>home_amt</column-name>
              <java-type>java.math.BigDecimal</java-type>
              <jdbc-type>DECIMAL</jdbc-type>
              <sql-type>NUMERIC(18,4)</sql-type>
              </cmp-field>

              We define the mapping in jaws.xml instead of standardjaws.xml because changing standardjaws doesnt seem to have any effect and still uses the mapping for IMAGE instead of NUMERIC.

              When inserting a value with a decimal part, such as new BigDecimal("1234.123"), the value stored in the database is just the integer part (1234).

              Are we using the correct type mapping?

              JBoss version is 2.4.10.