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
https://forums.phpfreaks.com/topic/75570-float-vs-decimal-in-mysql-data-types/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.