currency/Float/Double..
I want to store amounts of purchasing, which data type should I use in Database to store these amounts...
And what is the difference in between them...
| SitePoint Sponsor |


currency/Float/Double..
I want to store amounts of purchasing, which data type should I use in Database to store these amounts...
And what is the difference in between them...
[COLOR=SlateGray]
Web Developer @ VeriQual




The mysql documentation suggests using DECIMAL. http://dev.mysql.com/doc/refman/5.0/...ric-types.html
Yes, it should look like this in case of MySQL
Code sql:CREATE TABLE tablename ( price DOUBLE(10,2) NOT NULL );


do not use DOUBLE for money -- DOUBLE is the same as FLOAT and it is imprecise
see Problems with Floating-Point Comparisons
Yes, whatever you do, you do NOT want to use floats. Use an integer inside PHP, and in the database, use either DECIMAL or INTEGER. To use an integer, you need to make the smallest unit primary. Eg. instead of 1 dollar and 50 cents, you count 150 cents.
Last edited by kyberfabrikken; Jan 10, 2008 at 08:56. Reason: confusing typo there ..
Bookmarks