Answers for "round a number to the closest odd value"

0

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);
Posted by: Guest on January-07-2021

Code answers related to "round a number to the closest odd value"

Browse Popular Code Answers by Language