Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Vat rounding to 4 decimal places


timpea

Recommended Posts

Hi,

 

I am having problems with an Oscommerce site to do with products being added up with 4 decimal places, is it possible to change the site to only deal to 2 decimal places easily? I have no need for the site to go to 4 decimal places, i assume the only reason for this is to keep currency conversions more accurate?

 

I have read quite a few posts about this issue but most talk about order totals being incorrect when changing currency, but none really had an answer. The site does not have multiple currencies but may do in the future, but I can see no reason why we would ever need to be accurate to 4 decimal places.

 

Regards

Tim Pearson

Link to comment
Share on other sites

I have been researching this more and it seems it is not because of 4 decimal places. The problem is happening because the tax is being worked out by:

 

round(unit price * tax) * qty.

 

Rather than, what the clients software does:

 

round(unit price * qty * tax)

 

Reading the UK vat laws, it doesn't seem to mention much about how to work it out, other than the following:

17.5.1 Calculation based on lines of goods or services

If you wish to work out the VAT separately for a line of goods or services, which are included with other goods or services in the same invoice, you should calculate the separate amounts of VAT either by rounding:

* down to the nearest 0.1p - for example, 86.76p would be rounded down to 86.7p; or

* to the nearest 1p or 0.5p - for example, 86.76p would be rounded up to 87p.

Whatever you decide, you must be consistent.

The final total amount of VAT payable may be rounded down to the nearest whole penny.

 

17.5.2 Calculation based on tax per unit or per article

If you want to work out the VAT per unit or per article (for example, for use in price lists), you must work out the amounts of VAT either to:

* 4 digits after the decimal point and then round to 3 digits - for example, if the VAT is £0.0024, it should be rounded to £0.002 (0.2p); or

* the nearest 1p or 0.5p. If you decide to do this, you must not round the VAT down to “nil” on any unit or article that is liable at the standard or reduced rate - for example, if the VAT is £0.0024, it should be rounded to £0.005 (0.5p).

 

For me to change oscommerce to work out VAT the same as his software does do I need to change every place the price is shown, and remove the "per line total ex", as if I was to leave this is and use round(unit price * qty * tax) for the per line total inc" the prices wouldn't match.

 

Hope i explained myself well, anyone any ideas?

 

Thanks

Tim

Link to comment
Share on other sites

Hi,

 

Just to give an example for this, order 2 of a product at 7.75 with VAT (17.5% tax)

 

unit ex VAT 7.75

unit inc VAT 9.11

total ex VAT 15.50

total inc VAT 18.22

 

This price is worked out by unit inc VAT * 2

or you could have total inc VAT = 15.50 * 1.175 = 18.2125 = 18.21

 

Regards

Tim Pearson

Link to comment
Share on other sites

The problem just gets worse. I have an order with single quantities that is a penny out on the VAT, this is because the clients software works out the VAT on a per line basis and oscommerce seems to be working it out on a sub total cost.

 

I am getting confused to what is wrong here now, I think the way that (edit_orders.php, v2.8.5) may work out VAT different to the oscommerce order totals.

 

This following problem has deffinatly come from oscommerce's standard working out:

ex inc

1 x 0.38 0.45

1 x 0.75 0.88

1 x 6.20 7.29

 

sub total inc = 8.62

sub total ex = 7.33 (this plus VAT is £8.61)

 

£8.62 is the value that our client is getting on their software, oscommerce is using 8.61 even though this is not inline with the values above in the invoice.

 

Regards

Tim

Link to comment
Share on other sites

I have found exactly the problem and have sorted it. The problem was occuring from the clients software rounding the TAX on a perline basis to 2 decimal places. Oscommerce doesn't round the TAX, but does work it out per line, so the comulative tax on oscommerce is more accurate than our clients software.

 

I didn't keep a copy of all the files i have changed, but basically you are looking to change the bits of maths that work out the calcualtion from being

 

(tep_add_tax($products_price, $products_tax) * $quantity)

 

to be:

 

(tep_add_tax($products_price * $quantity, $products_tax) )

 

Regards

Tim

Link to comment
Share on other sites

  • 10 months later...

that takes care of all of the standard lines but dont forget to checkt he order totals. Ive found 1 missed was ot_tax. to fix change line 34 of

\catalog\includes\modules\order_total\ot_tax.php

////**iBridge tax fix** 'value' => $value);
'value' => tep_round($value, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) );
////**iBridge tax fix** end

 

HTH

 

Si.

Link to comment
Share on other sites

  • 10 months later...

Hi,

 

I had an issue with VAT (uk tax) not displaying correctly. I'm not sure if someone had modified the original rounding for OSC but anyway, it didn't work. The result is that:

 

On an order of £100, VAT of 15% would be applied as £14.99.

 

To correct this I amended tep_round in /includes/functions/general.php as follows:

 

//Changed to deal with tax rounding issue.

function tep_round($number, $round=2) {

 

$tempd = $number*pow(10,$round);

$tempd1 = round($tempd);

$number = $tempd1/pow(10,$round);

return $number;

}

 

The solution came from here: http://www.oscommerce.com/forums/lofiversion/i...hp?t255341.html

 

 

Hope that helps someone. :)

 

Search terms:

tep_round

VAT rounding

Tax rounding

1p 1 pence 1 penny out

issue

problem

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...