Let’s say you have a float 5.9476386 and an NSArray with the floats 1,4,8,12,… stored in ascending order.
NSArray *centers = [NSArray arrayWithObjects:
[NSNumber numberWithDouble:1],
[NSNumber numberWithDouble:4],
[NSNumber numberWithDouble:8],
[NSNumber numberWithDouble:12],
...
nil];
I want a new float that rounds the number to the closest number in the array.
So in this case the new float wil be 4 because 4 is the closest of the numbers of the array to 5.9476386.
How can i do this? I’m working in Objective-C/Cocoa
Assuming your array is sorted in ascending order