Page 1 of 1

what data type should i use in CURRENCY?

Posted: Tue Aug 19, 2008 8:00 pm
by zplits
Good day everyone. Does anyone here have an idea what is the best data type to use when dealing with money?

Need your advice. Thank you.

Re: what data type should i use in CURRENCY?

Posted: Tue Aug 19, 2008 10:14 pm
by Christopher
Usually there is a DECIMAL type that works well for money. Otherwise one if the FLOAT types. Be aware that floating point arithmetic can be problematic in almost all computer languages.

Re: what data type should i use in CURRENCY?

Posted: Tue Aug 19, 2008 10:49 pm
by zplits
can i use INT and just display it in a page formatted #,###.##?

Re: what data type should i use in CURRENCY?

Posted: Wed Aug 20, 2008 3:35 am
by onion2k
zplits wrote:can i use INT and just display it in a page formatted #,###.##?
You can, but all the prices in your database will have to be stored in whatever the smallest denomination of currency you have. That's pennies if you're in the UK like me. That's not really a problem but it's not the most efficient way of storing the data. Using a DECIMAL field means there'll be less wasted space on the server.

That is assuming you're using MySQL. Other databases, MSSQL Server for example, have a 'money' data type. You should use that if it's an option.