Forums / Bug Reports / incorrect subtotal calculation with Swedish Krona with 0 decimal symbols

incorrect subtotal calculation with Swedish Krona with 0 decimal symbols

Views: 1,354

Results 1 to 3 of 3
9 Apr 2012, 2:36 PM
#1
j_vovus avatar

j_vovus

New Zenner

Join Date:
Apr 2012
Posts:
4
Plugin Contributions:
0

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:

function zen_round($fNum, $iPrec = 2) {
        return empty($fNum) ? (int)0 : (int)(string)(round($fNum, $iPrec) * pow(10, $iPrec));
    }
10 Apr 2012, 6:29 AM
#2
j_vovus avatar

j_vovus

New Zenner

Join Date:
Apr 2012
Posts:
4
Plugin Contributions:
0

Re: incorrect subtotal calculation with Swedish Krona with 0 decimal symbols

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).

10 Apr 2012, 6:37 AM
#3
j_vovus avatar

j_vovus

New Zenner

Join Date:
Apr 2012
Posts:
4
Plugin Contributions:
0

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