Rounding Standards – Financial Calculations

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 … Read more

What class to use for money representation?

Never use a floating point number to represent money. Floating numbers do not represent numbers in decimal notation accurately. You would end with a nightmare of compound rounding errors, and unable to reliably convert between currencies. See Martin Fowler’s short essay on the subject. If you decide to write your own class, I recommend basing … Read more