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.
what data type should i use in CURRENCY?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: what data type should i use in CURRENCY?
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.
(#10850)
Re: what data type should i use in CURRENCY?
can i use INT and just display it in a page formatted #,###.##?
Re: what data type should i use in CURRENCY?
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.zplits wrote:can i use INT and just display it in a page formatted #,###.##?
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.