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.
- In New generic JDBC Persistence Service We would loose backwards compatibility to MYSQL bundel (or it/me has to be programmed a converter/switch).
- It is never as fast as now.
Does anyone have relevant experience?