2

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

Kami
  • 459
  • 1
  • 6
  • 27
martinwang1985
  • 528
  • 3
  • 26
  • 42

1 Answers1

2

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.

Community
  • 1
  • 1
Kalyan Chavali
  • 1,330
  • 8
  • 24