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.

Share:
11,874
martinwang1985
Author by

martinwang1985

Updated on June 04, 2022

Comments

  • martinwang1985
    martinwang1985 almost 2 years

    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