Page 1 of 1
Storing decimals into a database.
Posted: Thu Jun 15, 2006 7:25 pm
by a94060
Hi, i would liek to know what type of column i would use if i wanted to store a money amount into my database. If i run a query like
INSERT INTO offers (offer_name,offer_type,value) VALUES (noobs,free,10.99)
i want to be able to store that amount into the database.
Posted: Thu Jun 15, 2006 7:57 pm
by LiveFree
FLOAT
Posted: Thu Jun 15, 2006 8:26 pm
by a94060
so if i put the field as FLOAT,it will allow me to store values like 10.995,8.95,$8.97,1000.0987 ?
Posted: Thu Jun 15, 2006 9:05 pm
by timvw
It depends on your dbms... Just read the fine manual that comes with it...
Posted: Thu Jun 15, 2006 9:40 pm
by AKA Panama Jack
You can use float, decimal or even text if you are using mysql.
You can use text if you are not going to be performing math of any type on the field inside a query.
Decimal works great because it doesn't return the value as an exponential like the float will. We have been using decimal for just about everything in our databases instead of float. Also, float has a resolution problem due to the way the value is stored. If you have a float it CAN be returned slightly off and not the exact number you stored.
Posted: Fri Jun 16, 2006 5:33 am
by a94060
thanks. So that means if in doubt,use text since it keeps mostly the original input? i would purify the input with php right?