Zen Cart Logo
Forums / Currencies & Sales Taxes, VAT, GST, etc. / How is tax rounded off?

How is tax rounded off?

Views: 1,762

Results 1 to 5 of 5
8 Oct 2012, 2:36 PM
#1
4jdesigns avatar

4jdesigns

Zen Follower

Join Date:
Jul 2011
Posts:
106
Plugin Contributions:
0

How is tax rounded off?

Hi,

I'm busy adding to my cart the VAT value (20% UK) and I am a little confused on how zen cart calculates it as per the value on the checkout_payment page.

This is the code I have come up with to do the calculation on my cart:

<div class="cartTotalsColumns">
<?php
$tax_vat = 1.2; // 20% Sales tax, 1.2 to give me the amount minus 20% rather than 20% of...
$total_incl = $_SESSION['cart']->show_total(); // My carts total price inclusive of tax calculated by zen cart.
$total_excl = ($total_incl/$tax_vat)*100; // The inclusive amount divided by tax to give me exclusive amount (which I multiply by 100 for rounding off purposes as per the next line.
$total_round_down = floor($total_excl); // round off value to the lowest 10 ('floor' cannot do decimals hence line above).
$total_decimal = $total_round_down/100; // revert back to decimals for excl. amount.
$total_decimal2 = number_format($total_decimal,2, '.',''); // ensure 2 decimal places for excl. amount.
$total_vat = $total_incl - $total_decimal; // calculate actual tax amount.
$total_vat2 = number_format($total_vat,2, '.',''); // ensure 2 decimal places for tax amount.
?>
	<div class="cartTotalsRight">
		<?php echo $total_decimal2; ?>
		<br />
		<?php echo $total_vat2; ?>
		<br />
		<div id="cartSubTotal"><?php echo $cartShowTotal; ?></div>
	</div>
	<div class="cartTotalsLeft">
		Sub-Total excl.:
		<br />
		VAT (20% UK):
		<br />
		<div id="cartSubTotal">Cart Total:</div>
	</div>
</div>

I did a normal 'round($var, 2);' to round off my values but noticed it was inconsistent with the values shown on the checkout_payments page, hence the reason I have used 'floor' instead. The worked well through my tests but then hit one that did not have the same value.

So my question is, have I approached this wrongly or am I missing something?

Thanks,
Jay

8 Oct 2012, 4:54 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: How is tax rounded off?

Zen Cart calculates tax using the code inside the order-handling code along with also using the active order-totals modules.
It does NOT do it in the shopping cart page such as your example is doing. Thus the information is not yet available at that point.

8 Oct 2012, 6:08 PM
#3
4jdesigns avatar

4jdesigns

Zen Follower

Join Date:
Jul 2011
Posts:
106
Plugin Contributions:
0

Re: How is tax rounded off?

Hi Doc,

Tx for the reply. I understand its not yet available, that's why I am generating the my own exclusive amount and VAT from my carts total i.e. working out my totals backwards. It does work, but only has a couple of issues and I think it has to do with the way zen cart does its rounding off (may be wrong).

This is how I see Zen Cart doing it (in summary form):

*Item Excluding: *£10.00
*VAT: *20%
*VAT Amount: *(£10.00 x 20%) or (£10.00 x 0.20) = £2.00
*Inclusive Amount: *£10.00 + £2.00 = £12.00

And this is how get my totals:

*Item Including Tax: *£12.00
*VAT: *20%
*Item Excluding: *£12.00 / 1.2 = £10.00 = Exclusive amount
*VAT amount: *£12.00 - £10.00 = £2.00

Would I be correct in saying that my method of obtaining such values should give me accurate figures regardless of how zen cart does it?
And if so, the only discrepancy I can see that would show the values of each method being slightly different would be when it comes to rounding them off to 2 decimals.

Would I be correct in saying this?

9 Oct 2012, 4:37 AM
#4
drbyte avatar

drbyte

Sensei

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

Re: How is tax rounded off?

You're not going to like this response.

But, I'm not going to give you a yes or no because there are more factors involved, including products that are not taxable, shipping which is taxable, shipping which is not taxable, prices that are based on even numbers, prices that are based on odd numbers, prices that are multiple decimal places long, sales/specials/discounts based on percentages or based on fixed prices, and so on. Those things are all handled by the order processing and order totals etc code.

Feel free to suggest to your visitor that your simplified math is offering them an approximation and that the final price will be presented during checkout.

9 Oct 2012, 7:00 AM
#5
4jdesigns avatar

4jdesigns

Zen Follower

Join Date:
Jul 2011
Posts:
106
Plugin Contributions:
0

Re: How is tax rounded off?

Hey Doc,

Good response actually, because I forgot to take into account the non-taxable goods, probably better to just leave it as it was intended.

thanks for the advice.
Jay