chrmlr Posted November 24, 2007 Share Posted November 24, 2007 Is it possible to force float as the key for at least 2 decimals? The code I have now is rounding the numbers down to integers. I want to keep them as floating point numbers. function rank() { $query="select * from ladder"; $result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { $ascarray[($row['win'] / $row['lose'])] = $row['userid']; } krsort($ascarray); return $ascarray; Quote Link to comment Share on other sites More sharing options...
xyn Posted November 24, 2007 Share Posted November 24, 2007 Either 1. float($var); or 2. number_format($var, 2); Quote Link to comment Share on other sites More sharing options...
chrmlr Posted November 24, 2007 Author Share Posted November 24, 2007 Thanks for the reply. If I use float I get unknown function error. number_function doesn't return an error, but keeps them as whole numbers. Either 1. float($var); or 2. number_format($var, 2); Quote Link to comment Share on other sites More sharing options...
toplay Posted November 24, 2007 Share Posted November 24, 2007 You can change your query to let MySQL do it and order it for you. Example: $query="SELECT userid, win / lose AS avg_result FROM ladder ORDER BY avg_result ASC"; If you want results sorted by descending first, then change ASC to DESC. Quote Link to comment Share on other sites More sharing options...
xyn Posted November 24, 2007 Share Posted November 24, 2007 sorry. its number_format($var, 2, '.'); Quote Link to comment Share on other sites More sharing options...
chrmlr Posted November 25, 2007 Author Share Posted November 25, 2007 Thank you very much, that did the trick! You can change your query to let MySQL do it and order it for you. Example: $query="SELECT userid, win / lose AS avg_result FROM ladder ORDER BY avg_result ASC"; If you want results sorted by descending first, then change ASC to DESC. Quote Link to comment 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.