I have an application which retrieves a lot of numerical data from a server and saves it into a NSMUtableArray. Now the values are floats which look like 10.0; 11.2; 30.003; 109.23, etc.
Now I used the sortUsingSelector(@selector(compare:)) method to sort my array to find the largest and the smallest value. My output is following:
10.0
109.23
11.2
30.003
Now I suppose the compare: selector treats the values as strings and orders them accordingly. But thats not what I want. I want the values to be ordered according to their float value.
So my question is: Is there any way to sort the floats array according to their numerical value?
There may be a short cut for the comparison, and there’s no error checking, but something like this should do the trick:
Or you could just store the values as
NSNumberas they come in.