Problem with setBigDecimal method
Posted by: Emilio Fuoco
Date: October 08, 2004 07:03AM

Hi all,

I created a BigDecimal object with this method:

BigDecimal calibrate( String raw ){
return ( new BigDecimal( Integer.parseInt( raw ) * Math.pow( 2,-21 ) ).setScale( 21 ) );
}

After, I stored BigDecimal object value in the database (MySQL of course).
To do this I use this code:

LinkedList l = new LinkedList();
l.add( calibrate( "42714" ) );
...
...
preparedStatement.setObject( 1, l.get( 1 ), java.sql.types.DECIMAL, 21 );
...
...

Database column type is: numeric(22,21).
The problem is a precision lost.
Assume that BigDecimal object value is 0.02270412445068359375
In the database stored value is 0.022704124450683590000
I lost three digits !!

Can anyone help me?
Thanks.

Emilio

Options: ReplyQuote


Subject
Written By
Posted
Problem with setBigDecimal method
October 08, 2004 07:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.