How to use ResultSet of java to get precise value of float of mysql
11,874
You can try the below code
ResultSet rs = .....
BigDecimal myValue = rs.getBigDecimal("Column Name");
float myFloatValue = myValue.floatValue();
More about BigDecimal here.
You can have a look at this SOW post as well.
Author by
martinwang1985
Updated on June 04, 2022Comments
-
martinwang1985 almost 2 years
Is it possible in Java, I use
ResultSet
, to get the precise value offloat
ofmysql
?In my database of mysql, I have some values of
float
which are very long(for example, 123456789, more than 7 digits), I know if I useselect round(float_value_column,0)
I can get the precise value. But if I useResultSet.GetFloat
of java, I can get only the rounded value(123457000, just like in mysql I madeselect float_value_column
).May I ask, if I use
ResultSet.GetDouble
, may I get the precise value? or may I do likeResultSet.GetFloat(round(float_value_column,0))
?Thank you very much