Forum Moderators: coopster

Message Too Old, No Replies

which MySQL currency

what is the correct data type to use in MYSQL to hold currency values

         

nenorse

11:12 am on Apr 10, 2007 (gmt 0)

10+ Year Member



I am desgning a MySQL (v5.0) database, and being an ex-MSSQL type of guy I'm looking to use a currency field - however MySQL doesn't give me this option.

I saw a previous thread dated from 2005 discussing this where people were talking about using floats! er.. #*$!?#*!?

I am now using an INTEGER and have a currency table that holds the exponent (a la JDE One world/Peoplesoft). This is great, but a bit of a overkill...

any idea's on how to store cash in MySQL?

SP2

jatar_k

12:44 pm on Apr 10, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld nenorse,

you can just store them as strings using varchar

sawatkins

5:25 pm on Apr 10, 2007 (gmt 0)

10+ Year Member



What's currency, besides a number with a symbol attached to it?

My suggestion: use an integer. Format your currency in PHP before you INSERT and before you display to the end user.

Unless I'm missing something.

</g>

zCat

6:05 pm on Apr 10, 2007 (gmt 0)

10+ Year Member



Why not use DECIMAL? Apart from saving you from fiddling about converting between input and output (and increasing the chance of an error slipping in somewhere), it also enables you to do calculations on the value within the database.

P.S. this thread should really be in the Database forum.

coopster

12:39 am on Apr 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are a number of ways for Storing monetary values in MySQL [webmasterworld.com]. I use DECIMAL too (just like storing a string, basically). MySQL recommends [mysql.com] using the
DECIMAL
Numeric Type [mysql.com].