12-07-2011 09:33 PM
I have an array of floating numbers and I want to find a value in that array that is closest to a floating constant. For example if I have the array 5.9, 2.8, 3.7, 5.8, 6.9, and if I have the constant 5.4, how would I find the closest value to 5.4 in the array, which in this case would be 5.8. The only approach I can think of is to subtract each value in the array from 5.8 and find the minimum value of an array which would be created from the differences. Is there a better approach?
Thank you.
12-07-2011 09:37 PM