[JDBC ] java 'floating point double' causes rounding errors and too much decimal places

Found a real bad Problem,

I get very long decimals when data comes from databases saving OpenHab ‘DecimalType’ as java ‘double’.
(Therefore, I then introduced in my PostgreSQL bundle the parameter ‘numberDecimalcount’.)

But the database must return exactly what has been recorded, rounding is a bad idea, I think now!

Using double for saving Numbers causes (as in Mysql bundle) rounding trouble without end.

For Example 1.005 can not be represented in binary floating point double in java.
Have a look at this discussion: http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java

It seams the only right way, OpenHab ‘DecimalType’ not to save it as a ‘DOUBLE’ but as a jdbc-type ‘NUMERIC’ and ‘DECIMAL’ their Java equivalent is ‘BigDecimal’.
OpenHab DecimalType holds its data as BigDecimal anyway.
Rounding would be correct then.

  1. In New generic JDBC Persistence Service We would loose backwards compatibility to MYSQL bundel (or it/me has to be programmed a converter/switch).
  2. It is never as fast as now.

Any suggestions?
Does anyone have relevant experience?

Rgds
Helmut

Extended Generic JDBC Persistence Service with the ability to operate with ‘BigDecimal’. Solved!