我有以下函数,它迭代一个数组,在每个’Refund’对象上调用一个方法,该方法返回一个包含一些值的BigDecimal,例如20.45:
- private String getTransactionTotals(Refund[] refunds) {
- BigDecimal total = new BigDecimal(0.00);
- /*
- * Itterates over all the refund objects and adds
- * their amount payables together to get a total
- */
- for ( Refund refund : refunds ) {
- total.add(refund.getAmountPayable());
- }
- total = total.setScale(2,RoundingMode.CEILING);
- return total.toString();
- }
问题是它总是返回’0.00′.我知道我传递的数组不是null,而且’getAmountPayable()’函数返回的值也不是null或者等于0.我不知道我是不是一直盯着这太长了,我错过了明显的,一些帮助将非常感激.
PS – ‘getAmountPayble()’返回BigDecimal类型的值