Storing decimals into a database.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Storing decimals into a database.

Post 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.
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

FLOAT
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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 ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

It depends on your dbms... Just read the fine manual that comes with it...
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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?
Post Reply