Search code examples
mysqlcurrencydata-storage

MySQL currency storage


http://www.ozzu.com/programming-forum/mysql-storing-dollar-amounts-field-type-t106432.html

This forum seems to suggest you should store currency such as USD in its lowest common denominator ie: cents as a INT as opposed to a DECIMAL.

This seems somewhat silly to me. Anyone want to explain the reasoning for this especially why it's worth the time to code out formatting methods for the values?

Thanks.


Solution

  • Strictly speaking, storing as cents is simpler and it models the real world. Do you really collect and pay out fractional amounts of a dollar (1.255), or do you pay in cents (125)? I bet you pay and collect in cents.

    If you do deal with actual fractions, then use decimal, but try to avoid the repeating fractions.

    Generally, in accounting, you have to account for every penny, so you'll be dealing with remainders either way you go. If you stick with integers (cents), you'll more easily account for every penny.