java - add BigDecimal in order to have a running total -


i pick brians bigdecimal.. have method supposed have add running total amount due. here is:

private bigdecimal adduptotal(billrec bill, bigdecimal runningtotal) {     bigdecimal result = new bigdecimal(0);      if (bill.getbillinfo().getbillsummamtsize() > 0) {         (int x = 0; x < bill.getbillinfo().getbillsummamtsize(); x++) {             if ("totalamtdue".equals(bill.getbillinfo().getbillsummamt(x).getbillsummamtcode().getcode().tostring())) {                 result = runningtotal.add(bill.getbillinfo().getbillsummamt(x).getamt());                               }         }     }           return result; } 

the problem how call this? meaning when call how keep track of total? note can see passing runningtotal param not sure how keep value in method call from.

i suspect meant this:

private bigdecimal adduptotal(billrec bill, bigdecimal runningtotal) {     if (bill.getbillinfo().getbillsummamtsize() > 0) {         (int x = 0; x < bill.getbillinfo().getbillsummamtsize(); x++) {             if (...) {                 runningtotal = runningtotal.add(...);             }         }     }           return runningtotal; } 

you'd call using local variable keep running total:

bigdecimal runningtotal = bigdecimal.zero;  (billrec bill : bills) {     runningtotal = adduptotal(bill, runningtotal); } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -