Create Custom Math.Round() Method

using System;
namespace MyRoundMethod {
    class MyRoundMethod {
        static void MyRound(double myDoubleNum) {
            double myDouble = myDoubleNum;
            String decimalRightDigit = Convert.ToString(myDouble);
            decimalRightDigit = decimalRightDigit.Substring(decimalRightDigit.IndexOf("."));
            int decimalLeftDigit = (int) myDouble;
            double decimalRigtCont = Convert.ToDouble(decimalRightDigit);
            if (decimalRigtCont >= 0.5) {
                decimalLeftDigit = decimalLeftDigit + 1;
            }
            Console.WriteLine(decimalLeftDigit);
        }
        static void Main(string[] args) {
            MyRound(7849.56);
        }
    }
}
//Output 7850

 


Similar Articles