else {
var total = 0;
for (var i = 0; i < au.bills.length; i++) {
- total += parseFloat( au.bills[i].balance_owed() );
+ total += dollars_float_to_cents_integer( au.bills[i].balance_owed() );
}
- sdump('D_PATRON_UTILS','bills_total $$$ = ' + total + '\n');
- return '$' + total;
+ sdump('D_PATRON_UTILS','bills_total $$$ = ' + cents_as_dollars( total ) + '\n');
+ return cents_as_dollars( total );
}
}
}
}
+function dollars_float_to_cents_integer( money ) {
+ // careful to avoid fractions of pennies
+ var money_s = money.toString();
+ var dollars = money_s.split(".")[0];
+ var cents = money_s.split(".")[1];
+ var total = 0;
+ if (parseInt(cents)) total += parseInt(cents);
+ if (parseInt(dollars)) total += (parseInt(dollars) * 100);
+ return total;
+}
+
function cents_as_dollars( cents ) {
+ cents = cents.toString();
return '$' + cents.substr(0,cents.length-2) + '.' + cents.substr(cents.length - 2);
}