MySQL CAST/CONVERT to FLOAT Equivalent
Well I after a little searching I thought I would post this as it seems to be missing from Google results.
When converting/casting a string to a float value there is no specific function to use.
CAST(1.0 AS UNSIGNED) makes the value an unsigned integer, i.e. 1To get MySQL to really cast the value to a Float value you need to just +0.0 by doing this you can order the values appropriately (e.g. 1, 2, 5, 10, 19 rather than 1, 10, 19, 2, 5 like strings will do)
So to "cast" the string value to a Float/Double just do the following:
SELECT MyString2-0.0 AS MyFloat FROM MyTable ORDER BY MyFloat
I hope this helps anyone who is doing quick Google searches to find this information like I was.
Posted on Monday, Nov 22, 2010

0 Comments
Leave a Comment