martinwang1985
martinwang1985

Reputation: 556

How to use ResultSet of java to get precise value of float of mysql

Is it possible in Java, I use ResultSet, to get the precise value of float of mysql?

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 use select round(float_value_column,0) I can get the precise value. But if I use ResultSet.GetFloat of java, I can get only the rounded value(123457000, just like in mysql I made select float_value_column).

May I ask, if I use ResultSet.GetDouble, may I get the precise value? or may I do like ResultSet.GetFloat(round(float_value_column,0))?

Thank you very much

Upvotes: 2

Views: 12930

Answers (1)

Kalyan Chavali
Kalyan Chavali

Reputation: 1348

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.

Upvotes: 2

Related Questions