Anders Johansen
Anders Johansen

Reputation: 10455

Floating point precision: JDBC, double and DECIMAL, how to avoid loss?

I am copying some rows from a DB2 database usign a JDBC interface. My worry is this: Some columns are defined as DECIMAL 15. Internaly in DB2 these are stored as binary coded decimal. Copying these via a double precision variable in Java might lose some precision. As the program will run in a bank, this would definitely be a problem.

What's the best way to handle that?

Upvotes: 2

Views: 2481

Answers (1)

Buhake Sindi
Buhake Sindi

Reputation: 89169

Why not use ResultSet.getBigDecimal()?

The Javadoc states:

Retrieves the value of the designated column in the current row of this ResultSet object as a java.math.BigDecimal with full precision.

Upvotes: 4

Related Questions