views:

74

answers:

4

I am curious about the existence of any "rounding" standards" when it comes to the calculation of financial data. My initial thoughts are to perform rounding only when the data is being presented to the user (presentation layer).

If "rounded" data is then used for further calculations, should be use the "rounded" figure or the "raw" figure? Does anyone have any advice?

Please note that I am aware of different rounding methods, i.e. Bankers Rounding etc.

+2  A: 

The first and most important rule: use a decimal data type, never ever binary floating-point types.

When exactly rounding should be performed can be mandated by regulations, such as the conversion between the Euro and national currencies it replaced.

If there are no such rules, I'd do all calculations with high precision, and round only for presentation, i.e. not use rounded values for further calculations. This should yield the best overall precision.

Michael Borgwardt
Binary floating would be better than decimal with too little precision. $100⅔ is better represented in base 2 as "100.66666666666?????" than in base 10 as "100.67". But given enough decimal precison, I agree that a decimal data type is usually better.
Joe Koberg
@Joe: No, 100.67 would almost always be better because it's what people expect - and, more importantly, using a decimal type ensures that 100.01+100.07 = 100.08 rather than 200.07999999999998
Michael Borgwardt
The time for producing what people expect is at display time, and when rounding is performed there (e.g. '%0.2f'), people will see what they expect. if you are doing intermediate calculations, I think it is inappropriate to truncate/round to only 2 digits of precision. (Of course this depends on the computation at hand. Daily interest calculation rounded to 2 places might add 0.00 to the account every day. But customer invoice doesn't need 15 places of precision.)
Joe Koberg
I just checked, our core (mainframe) software stores 6 to 8 decimal places of precision for interest accrual on each account. At the end of the month the accrual field is rounded and applied to the balance. The goal is to always have "breathing room" of a couple extra digits. My point is that running up against the precision limit is worse than binary inexactness. (Even the decimal number will be inexact if you've exceeded the precision)
Joe Koberg
@Joe: None of that changes the fact that binary floats are unacceptable for financial calculations because they cannot accurately represent most decimal fractions at all and will introduce rounding errors in a completely unpredictable manner. Fortunately, it's a non-issue because any decimal type worth using will provide far more than 2 fractional digits if required.
Michael Borgwardt
Right, neither can a 2-place decimal precision reproduce most decimal fractions. Thats my only point, and I definitely recognize the value of decimal over binary in this situation.
Joe Koberg
A: 

Consider using scaled integers.

In other words, store whole numbers of pennies instead of fractional numbers of dollars.

Beth
A: 

I just asked a greybeard mainframe programmer at the financial software company I work for, and he said there is no well-known standard and it's up to programmer practice.

While statisticians have been aware of the rounding issue since at least 1906, it's difficult to find a financial standard endorsing it.

According to this site, the "European Commission report The Introduction of the Euro and the Rounding of Currency Amounts suggests that there had previously been no standard approach to rounding in banking."

In general, use a symmetric rounding mode no matter what base you are working in (base-2 or base-10).

This will avoid systematic bias during calculations.

Such a mode is Round-Half-To-Even, otherwise known as "bankers rounding".

Use language tools that allow you to specify the numeric context explicity, including the rounding and truncation modes. For example, Python's decimal module. The implicit assumptions made by the C library might not be appropriate for your computations.

http://en.wikipedia.org/wiki/Rounding#Rounding_to_integer

Joe Koberg
+1  A: 

Ive not seen the existence of "the one standard to rule them all" - there are any number of rounding rules (as you have referenced), and they seem to come into play based on industry/customer/and currency code (http://en.wikipedia.org/wiki/ISO_4217) - since not everyone uses 2 places after the decimal, the problem becomes even more complicated. At the end of the day, your customer needs to specify the rules they want to implement...

chrismh