1

When working with ResultSet getDouble(), I want to get the correct value from the database. The value stored in the database is 11.421351.when I do resultSet.getDouble("lon").I get 11.4213599999 like that. How would I get this to just print 11.421351?

Rini Antony
  • 39
  • 1
  • 3

1 Answers1

1

The double and float types in Java use floating point arithmetic, and are not exact. Instead, you should be using exact types:

  • In Java, use BigDecimal
  • In your SQL database, use NUMERIC or DECIMAL

Then, when you are accessing your result set from Java, use ResultSet#getBigDecimal to obtain the number with its full original precision.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360