### Author Topic: Canadian taxes on shipping : another rounding issue  (Read 4198 times)

#### Khaostar

• Jr. Member
• Posts: 58
##### Re: Canadian taxes on shipping : another rounding issue
« Reply #15 on: January 04, 2017, 15:46:19 pm »
Hi diri

Thanks for the possible solutiuon, but I don't think this is the right one to use.

As I said in my last post, the solution is siimply to calculate the taxes on the subtotal only, like every canadian shops are doing right now.

in fact, this is not really a rounding issue, but a problem with the addition of multiple rouded numbers. If we just add everything (products price, shipping price, etc) BEFORE applying the taxes, the problem is solved. But there is no options for that in VirtueMart actually.

For reference, here is a link that show what the taxes amounts are supposed to be based on the subtotal price : http://www.calculconversion.com/sales-tax-calculator-gst-qst.html

#### diri

• Beginner
• Posts: 28
##### Re: Canadian taxes on shipping : another rounding issue
« Reply #16 on: January 05, 2017, 06:21:33 am »
Hi Khaostar,

if it would be that simple ...

Part of trouble is a legislative regulation in many countries to show price with tax for each position of an order first (product's end price) before order is submitted for normal customers and many different regulations for taxes all around the world. You will always have problems with rounding in this situation - sum of product's end prices and totals of bill might differ because of rounding issues.

And there we are at rounding in display over here as well - reverse calculation has always a rounding problem.

To make understanding trouble of all calculations more worse you must dive deep in technical (hardware) based fundamentals. You will be astonished when you discover real precision of any CPU at bit level.

You will discover that there is kind of obligation to avoid divisions (multiplying with eg 0.05 is a division in reality) whenever it's possible or to use it only when a division is a trivial bit shift left or right. My tip given before is based on this knowledge (see comment "whatever" behind the numbers, here you see the reason).

#### Khaostar

• Jr. Member
• Posts: 58
##### Re: Canadian taxes on shipping : another rounding issue
« Reply #17 on: January 05, 2017, 14:24:34 pm »
Hi diri,

I understand your legislative argument, but here, in Quebec Canada, this is how we work. We HAVE to use the right calculation to obtain the right result. We have a way to calculate the taxes and every shop is calculating it that way : sum up everything and apply the taxes. It's not that complicated. But VirtueMart does not offer this kind of solution right now. That's why i'm trying to explain everything.

Here is a really easy exemple, step by step, with random prices. This is how we work here :

product 1 price :    5,50\$
product 2 price :  14,25\$
Shipping price :     5,50\$

Subtotal :            25,25\$
Tax 1 (5,00%) :     1,26\$   (25,25 * 0,05 = 1,2625 -> round that number)
Tax 2 (9,975%) :   2,52\$   (25,25 * 0,09975 = 2,5186875 -> round that number)
Total :                 29,03\$   (Subtotal + rounded taxes)

See? That simple. The taxes are calculated and rounded once on the subtotal only.

Actually, in virtuemart, the taxes are calculated on the products price, and then on the shipping price, and finally added together. It's not gonna give the same result. The way VirtueMart is calculating it is not an error, but that's not the way we need to calculate it here. This is why I ask for an option to calculate it the way we need.

#### diri

• Beginner
• Posts: 28
##### Re: Canadian taxes on shipping : another rounding issue
« Reply #18 on: January 07, 2017, 05:26:48 am »
Khaostar,

thank you for detailled explanation and the link but, even when I understand your need better I have an additional question now:

Are you using mathematical (aka geodetic or undisturbed rounding) or commercial rounding in Canada?

In Germany one should use commercial rounding which is a bit different. Most prominent software doing it wrong in this case is MS Excel - it performs mathematical (or half-round?) rounding. Therefore it's not really allowed to use it to generate bills over here except you put special nested rounding in your calculation preventing issues at decimals with trailing 5.

To explain it an example with two decimal places at display.

Number to be rounded 0.445
Mathematical rounding: 0.44
Commercial rounding: 0.45
edit:
This example extended to more decimal places in calculation:
Number to be rounded 0.444445
Mathematical rounding: 0.44
Commercial rounding: 0.45

You see we are at precision and legislative regulations even when calculation rules work according your needs (which could be applied at B2B over here at least).

#### Khaostar

• Jr. Member
• Posts: 58
##### Re: Canadian taxes on shipping : another rounding issue
« Reply #19 on: January 09, 2017, 13:59:25 pm »
Hi,

Thanks for your answer. You are right. The rounding mode is important too.

We are using the "round half up" method. (This is the default mode of php round function : http://php.net/manual/en/function.round.php)
So 0,445 become 0,45 and 0,444445 will be 0,44.
In fact, if the third digit is 5 or over, we add +1 to the second digit. If the third digit is 4 or under, the second digit stay the same.