This question already has an answer here:
- When should I use double instead of decimal? 12 answers
I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type is suitable for money computations? (ie. greater than $100 million)
Definitely use integer types for your money computations. This cannot be emphasized enough, since at first glance it might seem that a floating point type is adequate.
Here an example in python code:
looks pretty normal.
Now try this again with 10^20 Zimbabwe dollars
As you can see, the dollar disappeared.
If you use the integer type, it works fine: