0

在此处输入图像描述

谁能解释为什么会这样?如果我得到 SQL 总和,它的总和是正确的。我的代码如下。

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);
}
4

1 回答 1

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).

于 2013-10-18T05:40:54.927 回答