0

Why java calculation gives (double)40395.075*100=4039507.4999999995 instead 4039507.5 ? how to handle this in calculation.

Arun VS
  • 51
  • 1
  • 7
  • Possible duplicate of http://stackoverflow.com/questions/322749/retain-precision-with-double-in-java – Mapsy May 18 '17 at 05:28
  • Use `BigDecimal` class to handle such cases. It happens because of the way floating point values are stored in memory. – CocoCrisp May 18 '17 at 05:32
  • `java.text.DecimalFormat` might be useful – edt May 18 '17 at 05:35
  • 1
    A `double` cannot hold the number 40395.075. The best it can do is 40395.074999999997089616954326629638671875. See http://www.adambeneschan.com/How-Does-Floating-Point-Work/showfloat.php?floatvalue=40395.075&floattype=double for an explanation. – ajb May 18 '17 at 05:57

0 Answers0