Forum Moderators: coopster

Message Too Old, No Replies

mysql: what's the right type to use for a currency column?

         

partha

12:59 am on Mar 5, 2005 (gmt 0)

10+ Year Member



float? double? decimal? something else?
which one is correct to make sure monetary calculations using the decimal values (dollars and cents) are always right?

adamnichols45

10:50 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i have always used varchar and found no problems

curlykarl

11:11 am on Mar 5, 2005 (gmt 0)

10+ Year Member



HI,

I always use float 6,2

Karl :)

grandpa

11:17 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Float is the way to go, IMO.

Having said that, from the PHP documentation:

So never trust floating number results to the last digit and never compare floating point numbers for equality. If you really need higher precision, you should use the arbitrary precision math functions or gmp functions instead.

coopster

11:40 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You'll probably find many differences in opinion here. I tried starting a discussion on Storing monetary values in MySQL [webmasterworld.com] once to see if anybody else had done any extensive research but it didn't get very far.

My own testing showed that FLOAT takes up less storage space, but is not as accurate. If accuracy is key then it is probably best to listen to the authority [dev.mysql.com].

Relative Discussion:
[webmasterworld.com...]

grandpa

1:20 pm on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the end it would come down to your need. If the value is for display purposes only, use float. If you are using it in calculations use what will give you the accuracy you need.