From: Bill Erickson Date: Tue, 14 Jul 2015 18:25:34 +0000 (-0400) Subject: LP#1474566 Avoid credit card payment rounding X-Git-Tag: sprint4-merge-nov22~496 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d7fba543e4306114f5f78561e7448364438c09b5;p=working%2FEvergreen.git LP#1474566 Avoid credit card payment rounding Calculate total amount for credit payment as integers to avoid rounding errors w/ large sets of small billings. E.g. avoid trying to pay a fine of 9.999999999999 for a set of fines which should add up to 10.00. Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index a55877791a..666b402ad0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -321,7 +321,8 @@ sub make_payments { $amount =~ s/\$//og; # just to be safe my $trans = $xacts{$transid}; - $total_paid += $amount; + # add amounts as integers + $total_paid += (100 * $amount); my $org_id = $U->xact_org($transid, $e); @@ -396,6 +397,9 @@ sub make_payments { } # all payment objects have been created and inserted. + # return to decimal format, forcing X.YY format for consistency. + $total_paid = sprintf("%.2f", $total_paid / 100); + #### NO WRITES TO THE DB ABOVE THIS LINE -- THEY'LL ONLY BE DISCARDED ### $e->rollback;