On Using Integers

While integer types are usually binary and by definition do not support fractions, they are exact (no rounding errors when converting from decimal integers) and can be used as a sort of “poor man’s decimal type” by choosing an implicit fixed decimal point so that the smallest unit you work with can be represented as the integer 1. In practical terms, this is often put as: “To handle money, store and calculate everything in cents and format only the output”.

This works, but has a number of severe drawbacks:

Summary: using integers is not recommended. Do this only if there really is no better alternative at all.

© Published at floating-point-gui.de under the Creative Commons Attribution License (BY)

Fork me on GitHub