Floats for Currency
The cluster debates the dangers of using floating-point numbers for monetary values and calculations due to precision and rounding errors, advocating for decimal types, fixed-point integers, or arbitrary-precision alternatives in finance and accounting software.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Anyone who doesn't need more than 6 digits of decimal precision but can't be arsed to scale everything in to a fixed point format.
What is the issue with using floating point to represent money?
Have programmers stopped representing monetary values using floating point yet?
Why does scientific computing care about decimal arithmetic?
IBM Decimals are the standard for finance applications. Integers, not floating point.Floats don't have the precision required.
You’re misunderstanding the problem. It isn’t storage, it is calculation. You cannot do away with decimals because calculations are not always linear. There are several logarithms, exponents and root finding algorithms used in finance which you’d have to write several additional rules for if you can’t represent decimals. It’s not like mathematicians thought decimals were just a convenience so you don’t have to show large integers. They’re fundamentally not integers.
Using float for currency calculations is how you accumulate a bunch of rounding errors. Standard practice when dealing with money is to use an arbitrary-precision numerical type.
You don't need an exact number but customer data is universally decimal. Soon as you blindly convert that to IEE754 everything is now broken.
How do finance folks deal with decimals? Doesn't Excel use binary floats? Do they switch to integers?
e.g. money is badly represented as float.just my $0.0200000000001 on that topic.