storing money amounts in mysql storing money amounts in mysql mysql mysql

storing money amounts in mysql


Do not store money values as float, use the DECIMAL or NUMERIC type:

Documentation for MySQL Numeric Types

EDIT & clarification:

Float values are vulnerable to rounding errors are they have limited precision so unless you do not care that you only get 9.99 instead of 10.00 you should use DECIMAL/NUMERIC as they are fixed point numbers which do not have such problems.


It's not generally a good idea to store money as a float as rounding errors can occurr in calculations.

Consider using DECIMAL(10,2) instead.


Does it really matter if it stores is as 3.5, 3.50 or even 3.500?

What is really important is how it is displayed after it is retrieved from the db.

Or am I missing something here?

Also don't use a float, use a decimal. Float has all sorts of rounding issue and isn't very big.