Skip to content

Instantly share code, notes, and snippets.

@giorgi-ghviniashvili
Created July 20, 2018 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giorgi-ghviniashvili/093320018d003b59b473e9a53d83877a to your computer and use it in GitHub Desktop.
Save giorgi-ghviniashvili/093320018d003b59b473e9a53d83877a to your computer and use it in GitHub Desktop.
Round 2.5 to 3, 5.5 to 6, 3.5 to 4
int Round (double a)
{
int fl = Convert.ToInt32(Math.Floor(a));
if (a - fl == 0.5 && fl % 2 == 0) {
return fl + 1;
}
return Convert.ToInt32(Math.Round(a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment