round a number to the closest odd value code example
Example: round a number to the closest odd value
//rounds a number to the closest odd value
// sudo code----------------------------------------
x = 2 * floor (x/2) + 1
//for example 2.1 -> 3 , 3.9 -> 3 , 4.1 -> 5 etc...
//C#------------------------------------------------
Using System;
double x = 2.1;
x = 2 * Math.Floor(x/2) + 1; // x is now 3
Console.Write(x);