I am retrieving the numeric value from the resultset using getFloat.
but the value is getting rounded automatically above a certain limit. 1234.91 was not rounded but 9123441.91 was rounded to 9613042.0. What is the reason of this? I know that float can hold a lot larger value.
When I tried rs.getString(i) i got 9123441.91 as expected.
Can I safely get the numeric value using rs.getString(i) instead of getFloat?
Originally posted by Karan Jain: 1234.91 was not rounded but 9123441.91 was rounded to 9613042.0.
That's quite a lot of rounding from 912. . . to 961!
But joking aside, you realise that a float is only accurate to 6-7 decimal significant figures? 9123441.91 is 9 digits, and you can't expect a float to hold 9 digits.
Joined: Oct 13, 2005
More about this: I thought that I was getting confused between the SQL float type and the Java primitive float type. The ResultSet#getFloat() methods return a float, the Java primitive type, so that has only 6-7 sig fig. The SQL float type appears to be arbitrary precision, so you might be better seeing if you can get it into a BigDecimal.
Joined: May 30, 2007
Thanks for the reply guys!
I think I cannot use getFloat then as I will loose the precision.
I am currently using getString and it is working fine. Do you see any potential problem in that?