incorrect subtotal calculation with Swedish Krona with 0 decimal symbols
ZenCart 1.5.0, fresh install
I have some difference between sum of all products and subtotal amount. In last research it's 1 Swedish Krona with 0 decimal symbols (integer amounts).
BUG #1:
It caused by calculating subtotal in default currency (e.g. euro), and converting to Krona at the end.
So in abstract formula we have:
convert(price1+price2+price3) != convert(price1)+convert(price2)+convert(price3)
BUG #2:
Other bug in zen_round. It doesn't wrap all use cases of types casting. I loose 0.01 in euro on subtotal in this case:
Qty. Item Name Tax Total
1 x Disciples: Sacred Lands Linked 7.25% €96.53
1 x A Bug's Life "Multi Pak" Special 2003 Collectors Edition
Color: Green
Size: Medium
Version: 20th Century
Media Type: DVD 7.25% €39.67
2 x Microsoft IntelliMouse Explorer
Model: USB 7.25% €152.19
Subtotal: €288.38 (Should be 288.39)
Feel free to use my solution, it works perfectly for me:
PHP Code:
function zen_round($fNum, $iPrec = 2) {
return empty($fNum) ? (int)0 : (int)(string)(round($fNum, $iPrec) * pow(10, $iPrec));
}
Re: incorrect subtotal calculation with Swedish Krona with 0 decimal symbols
Quote:
Originally Posted by
j_vovus
I have some difference between sum of all products and subtotal amount. In last research it's 1 Swedish Krona with 0 decimal symbols (integer amounts).
I want to clarify some moments:
Quoted line is related to BUG #1 with Krona.
Besides, BUG #2 is tested in Euro with two decimal places (I think it's not depend on currency).
Re: incorrect subtotal calculation with Swedish Krona with 0 decimal symbols
Also, I'm sure, this bugs do not depend on the exact currency.
BUG #1 depends on any currency conversion (where ratio is not 1:1).
BUG #2 depends on PHP type casting during rounding.
Best regards,
Vladimir