Value closest to

I want to find a number value closest to another list.
Like the number 135, what is the closest value in a list there contains: 50, 100, 150, 200

Any ideas on how to do that? :slight_smile:


index: the absolute value of the difference

1 Like

I was thinking the same… but this way you have to turn Integer to a Double or the other way around to compare…

1 Like

The workaround:

1 Like

what’s the purpose of x:int[] ? @Schasfoortyoeri

@jshial This will make your values integer. this way you can compare them. before they were integer vs double.

As you can see in post 3 Value closest to the Object.Type from the minimum is System.Double and the object type from the Abs is System.Int64

1 Like

I did not know DesignScript has this kind of interesting syntax for casting a list. Always good to learn new stuff. Thx!:slightly_smiling_face:

But I think this step of casting the list is not a must. Math.Abs() returns Int.64 already.

That’s right :slight_smile:

Use this logic,

Logic.dyn (14.3 KB)


Now i had a chance to try your ideas, i think the problem is the codeblock, does that exist in a normal node??

The different is, that i have a list of numbers to find, and not just one, as in the example. I didn’t know it would make a different.

That custom node you have, i can’t find it in the Rhythm package. :sleepy:

Im using dynamo 2.0.3, revit 2018 and it is available
Try hot gear package