Real vs. Floating Point vs. Money

Have a look at What Every Computer Scientist Should Know About Floating Point Arithmetic.

Floating point numbers in computers don’t represent decimal fractions exactly. Instead, they represent binary fractions. Most fractional numbers don’t have an exact representation as a binary fraction, so there is some rounding going on. When such a rounded binary fraction is translated back to a decimal fraction, you get the effect you describe.

For storing money values, SQL databases normally provide a DECIMAL type that stores exact decimal digits. This format is slightly less efficient for computers to deal with, but it is quite useful when you want to avoid decimal rounding errors.

Leave a Comment