From d7fba543e4306114f5f78561e7448364438c09b5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 14 Jul 2015 14:25:34 -0400 Subject: [PATCH] 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 --- Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; -- 2.43.2