Improve float avoidance in outstanding bills tadl/lost_forgive_not_void_on_checkin
authorJeff Godin <jgodin@tadl.org>
Tue, 12 Jun 2012 17:40:46 +0000 (13:40 -0400)
committerJeff Godin <jgodin@tadl.org>
Tue, 12 Jun 2012 17:40:46 +0000 (13:40 -0400)
Simplify and improve floating point issue avoidance in
outstanding_bills_for_circ: fewer parentheses, better results.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm

index 70f9616..88d786a 100644 (file)
@@ -1827,16 +1827,16 @@ sub outstanding_bills_for_circ {
     # adjusting the amount for partially paid bills
     map {
             my $payment = $_;
-            my $paybal = $payment->amount;
+            my $paybal = $payment->amount * 100;
 
             while ($paybal > 0) {
                     # get next billing
                     my $bill = shift @{$bills};
-                    my $newbal = (($paybal*100) - ($bill->amount*100))/100;
+                    my $newbal = $paybal - $bill->amount*100;
                     if ($newbal < 0) {
                             $newbal = 0;
-                            my $new_bill_amount = (($bill->amount*100) - ($paybal*100))/100;
-                            $bill->amount($new_bill_amount);
+                            my $new_bill_amount = $bill->amount*100 - $paybal;
+                            $bill->amount($new_bill_amount/100);
                             unshift(@{$bills}, $bill); # put the partially-paid bill back on top of the stack
                     }