Created
July 20, 2018 08:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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