I always hear that floating point suffers from rounding errors and, therefore, decimal types must be used in place of the floating point for the finance. What do they mean by finance
? Do they consider money alone whereas gold, copper, iron, honey, wood, wool, cereals should still be accounted in real numbers or decimal type must always be used for any material asset? Because you know, if you lose .0000000004 cents it may be not as terrible as if you lose the same amount in the real material value. I just do not like the double standards.

- 29,088
- 9
- 83
- 120

- 1
- 8
- 40
- 64
2 Answers
"decimal types must be used in place of the floating point for the finance" mixes up orthogonal concepts. Binary is generally a bad idea for financial applications regardless of whether fractional values are represented with fixed-point or floating-point. Decimal floating-point was designed with financial computations as an application it would be useful for. You should simply stop listening to people who mix up these concepts.
The rules for rounding in financial computations are standardized; the standards express the rules with respect to decimal notation (one example). Therefore, the computing system used to carry out these computations should be able to represent decimal fractional values. It is not a question of .00000004 cents being a small amount, it is a question of applying mandatory standards.
In other words, both decimal and fixed-point can cause inaccuracies. Addition happens to be exact in fixed-point as long as it does not overflow, but fixed-point multiplication is no more exact than floating-point multiplication. Similarly, decimal cannot represent 1/3 exactly any more than binary can.
Decimal and/or fixed-point are often used to have the same inaccuracies as everyone else, rather than to eliminate inacuracies. ("everyone" including humans computing in decimal with pen and paper)

- 79,187
- 7
- 161
- 281
-
Do you mean that the standard demands decimal for finances alone but not for the other quantities? What about using decimal outside the financial sector? – Val Nov 07 '13 at 13:50
-
You need to ask whether there are specific rules about rounding of decimal fractions **in that context**. – Patricia Shanahan Nov 07 '13 at 13:54
-
@PatriciaShanahan The context is that people wonder why floating types cause inaccuracies in addition and others remind them that that this is the reason why decimals must be used for financial applications. Particularly, here is today's topmost question, http://stackoverflow.com/questions/19820297/why-does-changing-the-sum-order-returns-a-different-result#comment29486636_19820297. Though, this person seems changed his mind, after your answer :) – Val Nov 07 '13 at 14:05
If exact representation of decimal fractions matters more than exact representation of other fractions, use decimal arithmetic.
If there are a fixed number of digits after the decimal point, use fixed point. If not use floating point.
Generally, binary floating point is more efficient and compact, so use that if rounding of decimal fractions is no more undesirable than rounding of other calculations.
Decimal-for-finance does not always apply. For example, some compound interest rate estimates can be done faster and simpler using a floating point type with logarithm functions.
Does the iron come in some unit with decimal fractions and a need for exactness in calculations involving those fractions?

- 25,849
- 4
- 38
- 75