Forums / Upgrading to 1.5.x / Totals Off by a Penny!

Totals Off by a Penny!

Started by carol2848 on 15 Sep 2011, 7:00 PM · Views: 4,627

Results 1 to 20 of 21
15 Sep 2011, 7:00 PM
#1
carol2848 avatar

carol2848

New Zenner

Join Date:
Nov 2007
Posts:
78
Plugin Contributions:
0

Totals Off by a Penny!

Some customers have noticed that their totals are a penny off. I don't charge tax (digital goods). I believe the problem happens when the item is on sale (all my items are discounted 5%), and although it is rounded off for the published customer price, the full, say, four decimal points are used when totalling. And occasionally when several products are ordered, that will make the total a penny higher.

For instance, an item at 5% off is $14.2025. The published price on the store is $14.20. The next product discounts to $15.1525. The customer sees $15.15. But the store totals the full 4 decimal places (unseen to the customer), and their total is $29.36. But from what the customer can see, it should be $29.35.

I am wondering if I should change the number in Admin --> Currencies --> US Dollar to have only 2 decimal places. Would that hurt anything? Would that solve my problem?

I am running 1.3.9h.

Thanks in advance for your help!

16 Sep 2011, 12:38 AM
#2
drbyte avatar

drbyte

Sensei

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

Re: Totals Off by a Penny!

Fixed in v1.5.0

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Sep 2011, 7:52 AM
#3
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Totals Off by a Penny!

carol2848:

I am wondering if I should change the number in Admin --> Currencies --> US Dollar to have only 2 decimal places. Would that hurt anything? Would that solve my problem?
Won't hurt anything and should solve your problem.

The learning is in the doing.

Potent Products

16 Sep 2011, 10:23 AM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,743
Plugin Contributions:
56

Re: Totals Off by a Penny!

I have also seen cases where rounding errors after a price increase cause problems.
To fix them, back up your database and in phpMyAdmin, do this update:

update products set products_price = round(products_price, 2);

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

22 Sep 2011, 2:52 PM
#5
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

swguy:

I have also seen cases where rounding errors after a price increase cause problems.
To fix them, back up your database and in phpMyAdmin, do this update:

update products set products_price = round(products_price, 2);

Tried this fix, does not seem to work for me.

issue: one wax tart priced £1.00 = total okay
continue shopping add another wax tart priced £1.00 = total £1.99 ??
Do I now need to update my whole cart to v 1.5 to fix this? :unsure:
I entered the price in New product as £1.00
when I return to the same screen it reads as :lookaroun

Tax Class: UK V.A.T. 20%
Products Price (Net): 0.83
Products Price (Gross): 0.996

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

23 Sep 2011, 12:33 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,743
Plugin Contributions:
56

Re: Totals Off by a Penny!

Can you do a test in 1.5 and see if this works? The OP wasn't using embedded taxes the way you are.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

25 Sep 2011, 10:26 PM
#7
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

swguy:

Can you do a test in 1.5 and see if this works? The OP wasn't using embedded taxes the way you are.

If your question is @billy then yes I could I have a test site for trying stuff out I was planning on up-grading to 1.5 I'll give it a go arround mid week. Think I've got a few hours off from day job and setting up the wifes shop.

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 12:04 AM
#8
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

I know it took a while to get back on this, but been really busy.

Fact is it's still doing the wrong TAX calculation in Version 1.5

input tax rate 20%

pirice item at £1.00
calcultates TAX at £0.83

I'm no math expert but I think that's not right.

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 1:17 AM
#9
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

Hi guys, I had a little issue in v 1.3.9 that I think is carried over to 1.5, in that when using tax rates there seems to be a little discrepancy in the tax calculation. i.e.

Setting a Tax rate of 20% (as it shockingly is here in the UK)
Does not get calculated correctly in the add product page of the admin.

Tax Class: Taxable goods (20%)
Products Price (Net): 0.8333
Products Price (Gross): 1.00

Surely that's not correct? :no: :blink:
I know there was an issue with prices being out by a penny in the last version and there was this same tax issue.
I would just love it if someone explained it to me as my Math teacher would have failed me on this one just for showing my workings, even though the answer is right on the product info page and order totals at check out.

I am confussed :dontgetit:lookaroun

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 2:07 AM
#10
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Totals Off by a Penny!

That looks right to me to 4 decimal places. Why do you think it's wrong?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

13 Nov 2011, 3:13 AM
#11
drbyte avatar

drbyte

Sensei

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

Re: Totals Off by a Penny!

Exactly. Looks correct to me too.
Since you're doing tax-included-pricing, when you give it 1.00000 it calculates the base pre-tax (20%) price to 0.8333. If you multiply it forward again, adding the 20% tax back onto it, it still works out correctly as 1.0000 (correctly rounded up from the 5-decimals 0.99996 to the 4-decimals 1.0000).

I echo kuroi's comment: Why do you think it's wrong?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Nov 2011, 12:26 PM
#13
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,743
Plugin Contributions:
56

Re: Totals Off by a Penny!

BillyBoyle:

Tax Class: Taxable goods (20%)
Products Price (Net): 0.8333
Products Price (Gross): 1.00

Consider a product whole price is 1.00 with an embedded tax of 20%.

The tax component of this price is 1.00 - 1.0/(1+0.20) = 1 - 1/1.2 = 1 - 0.8333 = 0.1667.

Therefore, the net price is 1 - 0.1667 = 0.8333.

Remember the basic formula: VAT = $total - $total/(1+vat_percentage)

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

13 Nov 2011, 2:14 PM
#14
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

Cause 20% of 100 is 80 not 83.

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 2:39 PM
#16
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

OOPS timed out in editing > full reply below.

Cause 20% of 100 is 80 not 83.
But as I said if someone can explain it then I can understand it.
What has the number of decimal places got to do with it?
why is there a need to round down (to get the right answer)?
why not just a straight calculation?

I'm not a programer, but if I do the same calculation in excel and ask it to show 20 decimal places the answer is
£0.80000000000000000000.

I just want to understand what and how it's being caculated. Many cause I don't know and partly cause I want to reverse the calculation in Auto-facebook postings and show prices.

Anyway thanks for all the explanations: man Have I Got Some To Learn.

Thanks again guys.

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 2:56 PM
#17
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

DrByte:

Exactly. Looks correct to me too.
Since you're doing tax-included-pricing, when you give it 1.00000 it calculates the base pre-tax (20%) price to 0.8333. If you multiply it forward again, adding the 20% tax back onto it, it still works out correctly as 1.0000 (correctly rounded up from the 5-decimals 0.99996 to the 4-decimals 1.0000).

I echo kuroi's comment: Why do you think it's wrong?

There is a good reason you guys do the programming and we just spend a lot of time breaking it.

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 3:00 PM
#18
drbyte avatar

drbyte

Sensei

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

Re: Totals Off by a Penny!

Haha! I gather you're starting to see the logic in how it all works. Taxes are complicated ... especially when they're handled completely differently on the other side of the pond!

Cheers :)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Nov 2011, 3:00 PM
#19
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Totals Off by a Penny!

swguy:

Consider a product whole price is 1.00 with an embedded tax of 20%.

The tax component of this price is 1.00 - 1.0/(1+0.20) = 1 - 1/1.2 = 1 - 0.8333 = 0.1667.

Therefore, the net price is 1 - 0.1667 = 0.8333.

Remember the basic formula: VAT = $total - $total/(1+vat_percentage)

Thanks Scot, I appreciate the math leason and explanation from DrByte.

Seeing the formula written down makes it as clear as pea soup, but I do start to understand it now.

:clap::smartalec:

Today I am trying something different. Read the install.txt Read the FAQ Read the forum for answers; Then Install the mod. ;-)
AML Candles

13 Nov 2011, 4:02 PM
#20
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Totals Off by a Penny!

Don't get hung up on the idea that they're taxes. Just think of them as percentages and be grateful for the one benefit of working with 20% and not 17.5%.

Taxes are added as a percentage to a net price. You were trying to calculate it from the gross price so starting in the wrong place.

To work backwards from a gross price is more complex, which is where swguy's formula comes in.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)