Jump to content

Float vs Decimal in MySQL data types


s0c0

Recommended Posts

I have this query:

 

SELECT (sum(wsale_cost)*sum(quantity)) as cost FROM wsale_orderedProd WHERE invoice='14277333'

 

The wsale_cost datatype is float(5,2) and that query yeilds the following result: 170.50000190735 on a calculator it yields 170.50.  I realized that I can wrap ROUND(x,2) where x is the formula and get it look like 170.50, but why the hell does float do this? 

 

Should I instead be using decimal?  I've read that float has more efficient data storage.  Strange...can't find a good answer on google, maybe one of you can help.  For right now I'm switching to decimal(5,2) to avoid having to run an additional function inside my query.

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.