Data types make all the difference in the world when you’re designing your database. The choices you make now will affect the quality of your data, as well as application performance. I’m going to focus on one issue in this article: why you should always use decimals to represent money. Let’s jump in and see why that’s true.
An example of floats gone wrong
Let’s use a really, really simplified accounting ledger. It’s just three fields, an entry id, a customer id, and an amount, which has a float for a data type.
Create Table LedgerEntries ( LedgerEntryID Int Primary Key Auto_Increment Not Null ,CustomerID Int Not Null ,Amount Float Not Null );
Now let’s load some data.
Insert Into LedgerEntries (CustomerID, Amount)[Read more...]