Re: Monetary field in MySQL
| From: | Rolf Brusletto | Date: | Fri, 23 May 2003 17:46:58 +0000 |
| Subject: | Re: Monetary field in MySQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27997@lists.php.net to get a copy of this message | ||
I didn't realize that... makes sense being a (float) haha! First thing I did this morning was reply to that post, not get my daily coffe, maybe that was the problem :P
Thanks for the correction.
Rolf
John W. Holmes wrote:
*This message was transferred with a trial version of CommuniGate(tm) Pro*ithow can I have a field in MySQL that represents a monetary value i.e.You should use a DECIMAL column as you won't run into floating point error problems. Even though you say FLOAT(6,2), that's just precision. $12.25 may be stored in the database as 12.250000001 and meet the precision you gave. However, now if you're looking for a price == $12.25, this row will not be returned. DECIMAL columns are actually stored as strings, so there is no floating point errors. $12.25 is stored as "12.25" and there are no problems. Oh, and the obvious, this is not a PHP question!! ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/always has 2 zeros after the decimal point?you can use a float type. ALTER TABLEblahADDaMoneyFieldFLOAT(6,2) DEFAULT "0.00"