Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to round to nearest number in array c#

int[] array = {5,7,8,15,20};
int TargetNumber = 13;

var nearest = array.OrderBy(x => Math.Abs((long) x - targetNumber)).First();

//output = 15
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #nearest #number #array
ADD COMMENT
Topic
Name
5+8 =