oliverj777 Posted August 24, 2010 Share Posted August 24, 2010 Hello, As you may know, money is displayed like so: 10.50 (from where I am from its £10.50, but anyway ...) So what would you recommend as a type for SQL to save that value, I would prefer it to be numeric, but I would also like to save the decimal so when it comes to PHP, I can see what is pounds (dollars) and pence (cents) in which I will soon later add to a mathematical array. Thanks, Ollie! Quote Link to comment Share on other sites More sharing options...
shlumph Posted August 24, 2010 Share Posted August 24, 2010 Anything with decimals, use DOUBLE as a datatype and you should be good to go. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 24, 2010 Author Share Posted August 24, 2010 I get an error: SQL query: ALTER TABLE `users` CHANGE `due_balance` `due_balance` DOUBLE( 20 ) NOT NULL --- Do i need to do something special with the Length/Values? --- Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2010 Share Posted August 24, 2010 The DOUBLE data type requires a conversion into/out-of binary which introduces errors because some fractional values cannot be represented exactly in binary. You should use the DECIMAL data type, which are stored as BCD values, exactly as entered - The DECIMAL and NUMERIC data types are used to store exact numeric data values. In MySQL, NUMERIC is implemented as DECIMAL. These types are used to store values for which it is important to preserve exact precision, for example with monetary data. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 24, 2010 Author Share Posted August 24, 2010 sorted - I didn't know I had to change the length/value to a format of: decimal(#,#) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.