问题
I use T4SQLMX type 4 jdbc driver to read a double precision field from a SQL/MX table. The Actual value is 29963.26, however, the value read using the jdbc driver seems to be 29963.260000000002. This seems to be an issue even if I read it as resultset.getString() or resultset.getBigDecimal() because the driver always returns 29963.260000000002.
Similarly, value 99.76 is returned as 99.759999999999. We use CAIL to view the actual value 99.76 from the SQL/MX table, and SQL-Squirrel client and web-app uses sqlmx jdbc driver where we see the value as 99.759999999999
Has anyone faced this or similar issue and have a solution to this problem?
回答1:
I wrapped the double inside of a BigDecimal, then used setscale to 2 digits
BigDecimal.valueOf((resultset.getDouble(<column name here))).setScale(2, RoundingMode.HALF_UP));
来源:https://stackoverflow.com/questions/58841234/hp-nonstop-tandem-t4sqlmx-driver-double-precision-issue