Post Reply 
Rounding approach
04-13-2014, 11:41 AM (This post was last modified: 04-13-2014 11:45 AM by Dieter.)
Post: #4
RE: Rounding approach
(04-12-2014 07:29 PM)Tugdual Wrote:  I was wondering if there was a theory (or at least libraries or algorithms) to handle that properly?

The main problem is not the limited number of digits, it's the general rounding to two decimal places. Consider a very simple case like calculating the VAT amount when the gross price is given and the tax rate is 19%. This means that plus or minus cent gross price means 0,86 cent net price difference. Which inadvertedly leads to 1-cent-differences:

Code:
gross price: 103,00 EUR
./. VAT 19%:  16,45 EUR   ' exact: 16,4454
= net price:  86,55 EUR

  net price:  86,55 EUR
 +  VAT 19%:  16,44 EUR   ' exact: 16,4445
gross price: 102,99 EUR

The exact VAT amount is 16,4454 EUR which mathematically rounds to 16,45. However, your local legislation may state that the result has to be rounded down to the next lower cent. In this case it works:

Code:
gross price: 103,00 EUR
    VAT 19%:  16,44 EUR   ' exact: 16,4454
  net price:  86,56 EUR

  net price:  86,56 EUR
    VAT 19%:  16,44 EUR   ' exact: 16,4464
gross price: 103,00 EUR

So if and how to round is not just a mathematical question.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Rounding approach - Tugdual - 04-12-2014, 07:29 PM
RE: Rounding approach - Joe Horn - 04-13-2014, 06:44 AM
RE: Rounding approach - Paul Dale - 04-13-2014, 09:16 AM
RE: Rounding approach - Dieter - 04-13-2014 11:41 AM



User(s) browsing this thread: 1 Guest(s)