Loading ...
Sorry, an error occurred while loading the content.

about BigDecimal

Expand Messages
  • liang.yan@neusoft.com
    in xmldbms, BigDecimal is convert to long or double or integer. Data will be truncated, why not support BigDecimal to String?
    Message 1 of 4 , Aug 3, 2003
    View Source
    • 0 Attachment
      in xmldbms, BigDecimal is convert to long or double or integer. Data will be truncated, why not support BigDecimal to String?
    • Ronald Bourret
      Can you explain this more? If I remember correctly, conversions are done in three places: o When transferring data from XML to the database, XML-DBMS converts
      Message 2 of 4 , Aug 4, 2003
      View Source
      • 0 Attachment
        Can you explain this more?

        If I remember correctly, conversions are done in three places:

        o When transferring data from XML to the database, XML-DBMS converts
        from String to the column's data type.

        o When transferring data from the database to XML, XML-DBMS converts
        from the column's data type to String.

        o When setting parameters, XML-DBMS converts from the data type of the
        input object to the column's data type.

        What am I missing?

        -- Ron

        liang.yan@... wrote:
        >
        > in xmldbms, BigDecimal is convert to long or double or integer. Data will be truncated, why not support BigDecimal to String?
      • liang.yan@neusoft.com
        I use xmldbms version 2.0 alpha which is downloaded from cvs. when transferring data from database from XML,BigDecimal is converted to Long or Double. and
        Message 3 of 4 , Aug 5, 2003
        View Source
        • 0 Attachment
          I use xmldbms version 2.0 alpha which is downloaded from cvs.
          when transferring data from database from XML,BigDecimal is converted to Long or Double.
          and there is a error in converted to Long. and I add one condition:
          org.xmlmiddleware.conversions.ConverBigDecimal line133
          there is two condition before and i add b.subtract(new BigDecimal(b.longValue() )).doubleValue() !=0) :

          if((b.compareTo(MAX_LONG) == 1) || (b.compareTo(MIN_LONG) == -1)||b.subtract(new BigDecimal(b.longValue() )).doubleValue() !=0)

          so it works well.

          ----- Original Message -----
          From: "Ronald Bourret" <rpbourret@...>
          To: <xml-dbms@yahoogroups.com>
          Sent: Tuesday, August 05, 2003 2:26 PM
          Subject: Re: [xml-dbms] about BigDecimal


          > Can you explain this more?
          >
          > If I remember correctly, conversions are done in three places:
          >
          > o When transferring data from XML to the database, XML-DBMS converts
          > from String to the column's data type.
          >
          > o When transferring data from the database to XML, XML-DBMS converts
          > from the column's data type to String.
          >
          > o When setting parameters, XML-DBMS converts from the data type of the
          > input object to the column's data type.
          >
          > What am I missing?
          >
          > -- Ron
          >
          > liang.yan@... wrote:
          > >
          > > in xmldbms, BigDecimal is convert to long or double or integer. Data will be truncated, why not support BigDecimal to String?



          [Non-text portions of this message have been removed]
        • Ronald Bourret
          1) The conversions in ConvertBigDecimal are correct. That is, truncation of fractional digits is allowed. From the JavaDocs: The following rules from the ODBC
          Message 4 of 4 , Aug 10, 2003
          View Source
          • 0 Attachment
            1) The conversions in ConvertBigDecimal are correct. That is, truncation
            of fractional digits is allowed. From the JavaDocs:

            "The following rules from the ODBC specification are followed; the JDBC
            specification does not address these in spite of allowing the
            conversions they apply to:

            ...
            When converting from decimal to integer, truncation of fractional
            digits is allowed.
            ..."

            2) You are correct that the code shouldn't truncate fractional digits
            unless this is absolutely necessary. The bug is in
            NumberFormatter.format(Object), which has the following code:

            else if (o instanceof BigDecimal)
            {
            try
            {
            return
            formatter.format(ConvertBigDecimal.toLong((BigDecimal)o));
            }
            catch (XMLMiddlewareException e)
            {
            return
            formatter.format(ConvertBigDecimal.toDouble((BigDecimal)o));
            }
            }

            This should check for fractional digits and always convert to a double
            if they exist. (Code not yet compiled or tested.)

            else if (o instanceof BigDecimal)
            {
            BigDecimal b = (BigDecimal)o;

            // If the number is an integer, try to convert it to a long
            // before formatting it. This will ensure no loss of precision,
            // since long is an integral type.

            if (b.scale() <= 0)
            {
            try
            {
            return formatter.format(ConvertBigDecimal.toLong(b);
            }
            catch (XMLMiddlewareException e)
            {
            }
            }

            // If the number has fractional digits, or if it exceeds the
            // size of a long (in which case an exception is thrown above),
            // convert it to a double before formatting it.

            return formatter.format(ConvertBigDecimal.toDouble(b);
            }

            Note that it will be a while before I can get this tested and checked in
            to the CVS tree. However, you can test it yourself and see if it works.

            -- Ron

            liang.yan@... wrote:
            >
            > I use xmldbms version 2.0 alpha which is downloaded from cvs.
            > when transferring data from database from XML,BigDecimal is converted to Long or Double.
            > and there is a error in converted to Long. and I add one condition:
            > org.xmlmiddleware.conversions.ConverBigDecimal line133
            > there is two condition before and i add b.subtract(new BigDecimal(b.longValue() )).doubleValue() !=0) :
            >
            > if((b.compareTo(MAX_LONG) == 1) || (b.compareTo(MIN_LONG) == -1)||b.subtract(new BigDecimal(b.longValue() )).doubleValue() !=0)
            >
            > so it works well.
            >
            > ----- Original Message -----
            > From: "Ronald Bourret" <rpbourret@...>
            > To: <xml-dbms@yahoogroups.com>
            > Sent: Tuesday, August 05, 2003 2:26 PM
            > Subject: Re: [xml-dbms] about BigDecimal
            >
            > > Can you explain this more?
            > >
            > > If I remember correctly, conversions are done in three places:
            > >
            > > o When transferring data from XML to the database, XML-DBMS converts
            > > from String to the column's data type.
            > >
            > > o When transferring data from the database to XML, XML-DBMS converts
            > > from the column's data type to String.
            > >
            > > o When setting parameters, XML-DBMS converts from the data type of the
            > > input object to the column's data type.
            > >
            > > What am I missing?
            > >
            > > -- Ron
            > >
            > > liang.yan@... wrote:
            > > >
            > > > in xmldbms, BigDecimal is convert to long or double or integer. Data will be truncated, why not support BigDecimal to String?
            >
            > [Non-text portions of this message have been removed]
            >
            >
            > To post a message, send it to: xml-dbms@yahoogroups.com
            > To unsubscribe, send a blank message to: xml-dbms-unsubscribe@yahoogroups.com
            > Or join the newsgroup at: news://news.barkto.com/homeless.xml.xml-dbms
            >
            > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

            --
            Ronald Bourret
            Programming, Writing, and Research
            XML, Databases, and Schemas
            http://www.rpbourret.com
          Your message has been successfully submitted and would be delivered to recipients shortly.