Compare calculation

Startbeitrag von Gsmuser am 15.06.2009 08:06

how can i compare a serries of numbers and find the closest match
for eampel:
number1 is string =30 its also the string that we want to macth closest

number2 is string =38
number3 is string =25
number4 is string =21
number5 is string =28
number6 is string =33
number7 is string =59
closest macth woot be = string number 5 compared with string1
Ps the content of the number strings are from input they can be anything


is this somthing that cant be done?

von Gsmuser - am 15.06.2009 19:39

Place the values in an array
Calculate the difference with nbr1 and nbr 2
Remember the difference

In a loop Calculate each other difference (1 and 3, 1 and 4 etc)
If there is a smaller difference than nbr1 and nbr2 then rember the new nbr and the difference.
And so on.

If you compared all differences then you should get the closest nbr.

von Frans - am 15.06.2009 19:48
Zur Information: hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.