Jump to content

SQL - best type to save money value?


oliverj777

Recommended Posts

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!

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.