List:General Discussion« Previous MessageNext Message »
From:Jasper Bryant-Greene Date:September 26 2005 11:09pm
Subject:Re: money fields
View as plain text  
Daniel Kasak wrote:
> Chris Ripley wrote:
> 
>> What's a good (or best) field type for money or
>> currency data.  Mysql doesn't have a MONEY type for
>> structure, so what would I have the best luck with?
>>
> double
> 

No way. You should *never* use floating-point types for currency if you 
care about precision. You'll experience all sorts of weird rounding and 
comparison errors. See [1] for more information.

DECIMAL would suit your needs better -- from [2]: "The DECIMAL and 
NUMERIC types [...] are used to store values for which it is important 
to preserve exact precision, for example with monetary data."

[1] http://en.wikipedia.org/wiki/Floating_point
[2] http://dev.mysql.com/doc/mysql/en/numeric-types.html
-- 
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/
Thread
money fieldsChris Ripley27 Sep
  • Re: money fieldsDaniel Kasak27 Sep
    • Re: money fieldsJasper Bryant-Greene27 Sep
      • Re: money fieldsDaniel Kasak27 Sep
  • Re: money fieldsPeter Brawley27 Sep