Zen Cart Logo
Forums / General Questions / Errors in sub total.

Errors in sub total.

Views: 2,044

Results 1 to 20 of 23
1 Dec 2010, 5:47 PM
#1
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Errors in sub total.

Hey Guys,

I'm having a little trouble with the subtotal being slighty wrong and would like to know if someone could point me in the right direction.

Basicly it seems as if the subtotal is always out by a few pence. Here's an example ...

This is a breakdown of the total goods sold. I wont bother with the product details or the amount as this all ads up its just the subtotal.

6.70
59.94
22.92
33.84
15.16

total = 138.56

But the subtotal everywhere is 138.53 ?

Is this a rounding error ? I don't know but if someone could just even point me to where the sub total is being calculated that would be great :D I don't know if its a function or being accumulated from the individual products price but its a real head scratcher.

The only reason I am really bothered is at the company that I work they have a stock control system and this data needs to be exported out as a CSV and into there stock control system to deduct stock and generate customer invoices etc but the software programmer of the stock control system is being really funny about how things adds up and has coded the importer to reject bad maths lol :(

Any help at all would be much appreciated. :blush:

1 Dec 2010, 7:11 PM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Errors in sub total.

What version of Zencart ? There was a rounding error fix in 1.3.9e.

1 Dec 2010, 8:43 PM
#3
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Re: Errors in sub total.

It's 1.39g I think but there is quite a few mods installed and I have been known to just take the easy route and overwrite files lol is there a changelog or something I can look up the fix and patch the site up ?

1 Dec 2010, 8:52 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Errors in sub total.

drgr33n:

there is quite a few mods installed and I have been known to just take the easy route and overwrite files lolnot really something to "lol" about.
drgr33n:

is there a changelog or something I can look up the fix and patch the site up ?
If you're blindly replacing files willy-nilly, then a changelog isn't likely to serve its intended purpose.
Nevertheless, if you look in the /docs/ folder of your site files you'll see the documentation about what's changed between releases and the files involved.

1 Dec 2010, 9:22 PM
#5
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Re: Errors in sub total.

I know i was a bit stupid. Ok well thanks for your help.

6 Dec 2010, 8:53 AM
#6
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Re: Errors in sub total.

I can't seem to find info about the rounding error fix in 1.39e ? I found a bug fix related to PAYPAY shipping tax but thats it. Does anyone have the bugforum reference number ?

6 Dec 2010, 9:48 AM
#7
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Re: Errors in sub total.

Well I've been through all the changes made in 1.3.9e and it seems as all my files are up to the current version of zen cart but I'm still getting this rounding error ? If I disable tax from our store everything adds up but if I turn tax on I'm getting a few pence out on the subtotal ?

6 Dec 2010, 1:43 PM
#8
drgr33n avatar

drgr33n

New Zenner

Join Date:
Oct 2010
Posts:
84
Plugin Contributions:
0

Re: Errors in sub total.

Well I've been on this one all day and still can't figure it out :( I've pin pointed it to a rounding error.

I think whats happening is that when the tax is added on each individual price and then rounded the prices are missing the odd half pence here and there. And when I add up the individual prices and then compare this to the subtotal its always going to be a few pence out due to this.

I think the best way for me to proceed is to change the way zen cart calculates the subtotal by adding the tax to each individual product and then adding all the rounded figures together to come up with the sub total ?

Could someone point me to the function / module that's responsible for calculating the total ?

11 Dec 2010, 10:32 PM
#9
protostack avatar

protostack

New Zenner

Join Date:
Jul 2008
Posts:
29
Plugin Contributions:
0

Re: Errors in sub total.

I've been experiencing a rounding problem since 1.39d (problem may have existed before but hadn't noticed).

I can assure you that the problem still eists after 1.39e. I am running 1.39g right now and the problem persists.

It only happens when I have quantity discounts (expressed as a percentage).

For example I have a product (Polarized Header 4 Pin Female) which sells for $0.31 each or $0.28 each for 10 or more.

I had an order the other day which had

64 x Polarized Header 4 Pin Female $17.92
=====
Subtotal $17.86
Freight $5.00
Freight Insurance $0.89
=====
Total $23.75

The quantity discount on the product is expressed as a percentage (10%) and it so happens that 64 * 0.31 * .9 = 17.856.

The way it used to work (1.38x) was the subtotal = sum (qty * round(price*(1 -discount/100))) but now it seems like round(sum(qty * (1-discount/100)))

Daniel.

20 Oct 2011, 12:59 PM
#10
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

I have the same error

Product 1 - price 10.50 - discount 15% - 8.93
Product 2 - price 11 - discount 15% - 9.35
Subtotal - 18.27 (instead of 18.28)

It seems an error in round .xx5

I have version 1.3.9h

And yes with 1.3.8x this problem was not present

Any idea how to fix it?

20 Oct 2011, 4:09 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Errors in sub total.

incircolo:

Any idea how to fix it?
v1.5.0.

20 Oct 2011, 4:18 PM
#12
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

mmm i can't wait for 1.5, maybe it's an easy mod
The single product price is ok, the problem is with sub-total.

20 Oct 2011, 4:37 PM
#13
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

Why in administration, in whoisonline i can see a correct subtotal value, when the customer has products in cart, and in front-end the customer has an incorrect subtotal value ?
In which file is calculated the subtotal value for front-end and order ?

20 Oct 2011, 4:45 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Errors in sub total.

There are many files involved in the order handling process.

All the rounding issues which you're talking about are fixed in v1.5

20 Oct 2011, 4:54 PM
#15
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

This kind of bug can give problems if the payment is PayPalEC ?
Does ZenCart pass incoherent data to PayPal?

20 Oct 2011, 8:14 PM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Errors in sub total.

I think the word "incoherent" is inappropriate here, at least as far as Websters is concerned.

It passes whatever it calculates. So, if, as described earlier in this thread, you're using percent discounts or taxes that cause the calculations to result in a penny-difference with rounding, then that will have its impacts wherever those numbers are calculated. PayPal will read whatever is supplied to it. And, as far as PayPal goes, ZC attempts to ensure that any mismatch in line-item values is mitigated by taking fallback actions to submit less detailed information when necessary to allow the transaction to go through.

As I said, the rounding/calculation issues are fixed in the next version.

20 Oct 2011, 9:01 PM
#17
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

When a stable-production version of 1.5 is planned for ?
As you can imagine, the problem is now, but anyway the important thing is that at least there are no problems with PayPal transactions.

20 Oct 2011, 9:06 PM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Errors in sub total.

See the News & Announcements section of the forum for all release announcements. Subscribe yourself to that forum if you wish to be notified by email when announcements are posted.

20 Oct 2011, 9:49 PM
#19
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

I'm already subscribed. Anyway thanks for your great work DrByte, which is much-much appreciated.

20 Oct 2011, 10:11 PM
#20
incircolo avatar

incircolo

New Zenner

Join Date:
Aug 2009
Posts:
50
Plugin Contributions:
0

Re: Errors in sub total.

dear drbyte
I've found this on the forum that seems to fix the problem.
http://www.zen-cart.com/forum/showpost.php?p=680733&postcount=21
Is it possible?

this

  function zen_round($value, $precision) {
  $value = (int)$value + (round((ceil(round(($value - (int) $value)*pow(10, $precision), $precision)))/pow(10, $precision), $precision));
    return $value;
  }

seems to work better than the original

  function zen_round($value, $precision) {
    $value =  round($value *pow(10,$precision),0);
    $value = $value/pow(10,$precision);
    return $value;
  }

What do you think about it?