Rounding Issue with Tax
DevRaeph opened this issue · 2 comments
DevRaeph commented
Rounding of taxed items is not correct.
Net Val = 4,99
Taxed Val = 5,99
Tax Amount = 20%
Tried to add Product with quantitiy 4, price in cents 499
Total = 23,95
With Calculator total = 23,96
Edit:
Found out there is a precision issue:
`$tax = round(499 * (20/100), 2) * 4;
//Your function for calculation Taxes with one item it's working fine, with for there is a missung cent
echo LaraCart::formatMoney(
$tax,
"de_AT.UTF-8",
"EUR",
false
);`
Tax per item should be 1 exactily -> is rounded 99.8
i would reccomend to use PHP Money lib, example:
$money = Money::EUR(499);
$taxAlt = $money->multiply((20/100),MONEY::ROUND_HALF_POSITIVE_INFINITY);
echo LaraCart::formatMoney(
$taxAlt->getAmount(),
"de_AT.UTF-8",
"EUR",
false
);
Outputs the exact 100
lukepolo commented
Ill be working on simplifying the rounding bit, it should only round once we get to the totals~
lukepolo commented
I have made the changes in the new branch , should be coming out soon. Note: this is a massive breaking change.