There is not an easy answer on that. The question is what you want to store:
- is it the final currency amount of an invoice?
- or is it maybe the line amount of an document line (e.g. the line amount of an invoice line)?
Final currency amount
I only know currencies with 2 decimal places but according to this doc from Oracle the ISO standard says 3 decimal places are allowed in a currency. (I couldn't find the ISO document Oracle is mentioning here).
Interesting: SQL Server has a data type money
and smallmoney
which supports 4 decimal places. Don't know how they came up with that, maybe because of rounding issues (see below).
Line amount of an document line
You might want to make sure that you don't run into rounding issues and therefore use more than 3 decimal places where you have a 'sub-amount' of the total amount of a document (e.g. invoice).
Example:
Line |
Qty |
Price |
Discount |
Line Amount |
Line Amount rounded 2 decimal places |
---|
Item A |
5 |
79.99 |
3% |
387.9515 |
387.95 |
Item B |
2 |
56.12 |
3% |
108.8728 |
108.87 |
Item C |
1 |
12.19 |
3% |
11.8243 |
11.82 |
Total |
|
|
|
508.65 |
508.64 |
We end up having 1 cent rounding difference when we round the line amount to two decimal places. You can play this game with other numbers where you run into differences with more than three decimal places.
The most systems I worked with use different approaches:
- use 5 or more decimal places in the line amount. With 5 decimal places, most if these rounding issues should be soved. I saw ERP systems with 10 decimal places, but I saw this more like an bad application design.
- 'enforce' rounding in the line amount to the currency amount max. decimal places. This makes sence when you want to print the 'Line amount' in the invoice and you don't want to make printed invoices where the rounded line amount does not match up with the total
- make it configurable for the application how many decimal places shall be used.
- adding a 'rouding' line to a document to discount the rounding in case the rounding issues would be to the disadventage of the customer.
- warn the application user when rounding issues occur and ask for how the system shall handle them
It is up to your application design how you want to deal with rounding issues in document lines.
Money
data type? – Oded