From ad1e63fa3a64af385ebdb4782ea0368050f4aa7e Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sat, 9 Dec 2017 17:08:05 +0000 Subject: [PATCH] Fix rounding issue with GST and discounts (#1437) --- application/libraries/Sale_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 1567d2bb3..ad28bd603 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -505,7 +505,7 @@ class Sale_lib $sales_total = $this->get_total(); $amount_due = bcsub($sales_total, $payment_total); $precision = totals_decimals(); - $rounded_due = bccomp(round($amount_due, $precision, PHP_ROUND_HALF_EVEN), 0, $precision); + $rounded_due = bccomp(round($amount_due, $precision, PHP_ROUND_HALF_UP), 0, $precision); // take care of rounding error introduced by round tripping payment amount to the browser return $rounded_due == 0 ? 0 : $amount_due; } @@ -1197,7 +1197,7 @@ class Sale_lib $total = bcmul($quantity, $price); $discount_fraction = bcdiv($discount_percentage, 100); - return bcmul($total, $discount_fraction); + return round(bcmul($total, $discount_fraction), totals_decimals(), PHP_ROUND_HALF_UP); } public function get_item_tax($quantity, $price, $discount_percentage, $tax_percentage)