0

enter image description here

Can anyone please explain why this happen? If i get SQL sum its total correct. My code is below.

private void calTotalSMV() {

    double ttl_smv = 0;
    for (int x = 0; x < OBJ_CALLER.DTMEMERG.getRowCount(); x++) {
        ttl_smv += Double.parseDouble(OBJ_CALLER.DTMEMERG.getValueAt(x, 3).toString());
        System.out.println("total smv = " + ttl_smv);
    }
    jLabel23.setText("" + ttl_smv);
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
maXfenda
  • 214
  • 3
  • 10

1 Answers1

0

It is not an error, it's all about precision for floating point numbers(float, double).If you want more accurate results, use BigDecimal. Easier solutions would be rounding(Math.round function) and formatting(NumberFormat).

Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43