s0c0 Posted October 31, 2007 Share Posted October 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75570-float-vs-decimal-in-mysql-data-types/ Share on other sites More sharing options...
fenway Posted November 1, 2007 Share Posted November 1, 2007 You rarely want FLOAT... especially not for anything having to do with currency. Quote Link to comment https://forums.phpfreaks.com/topic/75570-float-vs-decimal-in-mysql-data-types/#findComment-382733 Share on other sites More sharing options...
aschk Posted November 1, 2007 Share Posted November 1, 2007 If you want to know why it's doing this read this : http://docs.sun.com/source/806-3568/ncg_goldberg.html Quote Link to comment https://forums.phpfreaks.com/topic/75570-float-vs-decimal-in-mysql-data-types/#findComment-382815 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.