4 ms·
In a related topic. It is surprising that many business applications use floating values to represent currency. That is very wrong, because it creates rounding
by huherto 16y ago
In a related topic. It is surprising that many business applications use floating values to represent currency. That is very wrong, because it creates rounding errors that accumulate. A common symptom is if you have an invoice where the total cannot be calculated from the detail using a regular hand held calculator.
How should you handle currency? At least in Java there is a BigDecimal that should be used instead. Look at the divide() method to see how you can have different rounding behaviors. As an alternative, some people use integers with a convention that there is a decimal point in the nth position. Just remember that floating point shouldn't be used for currency.
- Natsu 16y ago> How should you handle currency? Cents, or fractions thereof, fit into an integer, unless you have to do currency conversion. If you have to do that, you hire a programmer who has studied numerical analysis. It's a fun course, but very hard. I remember studying with a textbook the professor himself wrote and not being able to find much information online. This has changed quite a bit in the past decade or so. Nowadays, you can find useful stuff like this online: http://en.wikibooks.org/wiki/Real_Analysis http://en.wikibooks.org/wiki/Real_Analysis http://floating-point-gui.de/ http://floating-point-gui.de/ http://docs.sun.com/source/806-3568/ncg_goldberg.html http://docs.sun.com/source/806-3568/ncg_goldberg.html