Storing money values in MySQL
| From: | tg-php at gryffyndevelopment dot com | Date: | Thu, 19 Jan 2006 22:26:41 +0000 |
| Subject: | Storing money values in MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-41081@lists.php.net to get a copy of this message | ||
Again.. your forgiveness. This is a MySQL question. If the MySQL mailing lists would include a
[MySQL Help] tag in their subject lines, I'd use them. What I receive from them is difficult
to distinguish from spam half the time so I gave up.
We had a problem a few months ago and now I can't find my notes relating to it. The problem we
had involved storing money data as either float or decimal and having the 'cents' round
improperly. And it wasn't just a matter of 10.05 becoming 10.06, it was something along the
lines of 10.05 becoming 10.12.
This was when just a straight UPDATE was performed. I remember doing it manually, not even through
PHP, using absolutely no math functions, just a totally straight:
UPDATE SomeTable SET AmtOwed = 10.74
Someone made a recommendation of "never use SOMETYPE for money.. you should use SOMEOTHERTYPE
instead".
I've spent the better part of the afternoon trying to find my notes, recreate the bug in our
database, search online for the discussion I had then or other information about this. So far
I'm coming up empty.
We're retooling some of our database and trying to make it more efficient and accurate and this
is on the list of things to doublecheck. If anyone has any comments, criticisms, information,
etc... I'd love to hear them.
We're running MySQL 4.1.11-standard.
Thanks!
-TG
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.