You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Satheesh Bandaram (JIRA)" <de...@db.apache.org> on 2005/02/09 20:49:12 UTC

[jira] Closed: (DERBY-123) Derby incorrectly rounds double values down during insert into NUMERIC

     [ http://issues.apache.org/jira/browse/DERBY-123?page=history ]
     
Satheesh Bandaram closed DERBY-123:
-----------------------------------


Fix submitted to trunk version.

> Derby incorrectly rounds double values down during insert into NUMERIC
> ----------------------------------------------------------------------
>
>          Key: DERBY-123
>          URL: http://issues.apache.org/jira/browse/DERBY-123
>      Project: Derby
>         Type: Bug
>   Components: SQL
>     Versions: 10.0.2.1
>  Environment: Linux JDK 1.4.2
>     Reporter: Geoff Soutter
>      Fix For: 10.1.0.0

>
> When inserting a double value into a field defined as NUMERIC(a,b) using PreparedStatement.setDouble(), Derby may incorrectly round the number down. 
> For example, a NUMERIC(5,2) field with a double = 4.64 ends up with a value of 4.63 in the database. This works fine in Oracle and other databases.
> The problem occurs because double cannot represent 4.64 exactly, so the actual value is 4.6399999... SQLDecimal.setCoreValue uses BigDecimal(double) which constructs a BigDecimal of 4.6399999... and then SQLDecimal.setWidth uses value.setScale(desiredScale, BigDecimal.ROUND_DOWN); Note that BigDecimal javadoc recommends that the double constructor be avoided for this reason.
> One fix appears to be to change SQLDecimal.setCoreValue(double) to avoid using the double constructor of BigDecimal. Using Double.toString() and BigDecimal(String) looks as if it would work as expected, because Double.toString() has "special rounding abilities" and converts 4.639999... back to 4.64.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira