Gérard Lochon wrote:
You have a net value, 2 decimals provided, then
you calculate the taxes round(rate*net,2),
and then you add the net and the taxes to get the gross.

And the result can be different from round(net*(1+rate),2).

The true gross is always an addition (net+taxes), and
never a multiplication basis, this avoiding rounding deltas.

Going with the 21% VAT thought I'd test this out so knocked up a quick program (below) to go up from 0.01 until you get a difference in the calculation. You must go up to 18586.50 where the VAT is 3903.17 giving total of 22489.67 whereas the other method gives 22489.66

A bit more checking and the 0.01 error is also due to rounding errors. When nNum is 18586.5 in the program below
nNum  = 18586.499999958650
nVat =  3903.170000000000
nGross = 22489.669999958650
nMulti = 22489.660000000000 - This only comes out at this value because nNum is below the exact value it should be. If you put into a calculator:
18586.5 * 1.21 = 22489.665 which should round up to 22489.67

In the program below if you put in
nNum = round(nNum,2) at the start of the loop you get no differences up to 200,000. I'm sure if you go higher you will find some.

Think it's time to check a few programs ;-)

Peter

CLEAR
nNum = 0.01
nRate = 0.21
DO WHILE nNum < 100000
  nVat = ROUND(nNum*nRate,2)
  nGross = nNum + nVat
  nMulti = ROUND(nNum*(1+nRate),2)
  IF nGross <> nMulti
? 'Value ' + STR(nNum,9,2) + ' differs. ' + STR(nGross,10,2) + STR(nMulti,10,2)
  ENDIF
  nNum = nNum + 0.01
ENDDO



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to