Exemple #1
0
        public static string AddDecimal(string decimal1, string decimal2)
        {
            int need1 = CalculateUtilities.ConvertDecimal(ref decimal1);
            int need2 = CalculateUtilities.ConvertDecimal(ref decimal2);
            int need  = 0;

            if (need1 > need2)
            {
                need = need1;
                int temp = need1 - need2;
                for (int i = 0; i < temp; i++)
                {
                    decimal2 += '0';
                }
            }
            else
            {
                need = need2;
                int temp = need2 - need1;
                for (int i = 0; i < temp; i++)
                {
                    decimal1 += '0';
                }
            }
            string result = AddInteger(decimal1, decimal2);

            if (need == 0)
            {
                return(result);
            }
            return(UnaryOperatorService.Devision10(result, need));
        }
Exemple #2
0
        public static string MutipilationDecimal(string decimal1, string decimal2)
        {
            if (decimal2 == "0")
            {
                throw new DivideByZeroException();
            }
            int    need1  = CalculateUtilities.ConvertDecimal(ref decimal1);
            int    need2  = CalculateUtilities.ConvertDecimal(ref decimal2);
            int    need   = need1 + need2;
            string result = MutipilationInteger(decimal1, decimal2);

            if (need == 0)
            {
                return(result);
            }
            return(UnaryOperatorService.Devision10(result, need));
        }
        public static string SquareDecimal(string _decimal, int baseNumber, int accuracy)
        {
            int need = CalculateUtilities.ConvertDecimal(ref _decimal);
            int temp = need / baseNumber;
            int more = 0;

            if (need % baseNumber > 0)
            {
                more = need * (temp + 1) - need;
            }
            for (int i = 0; i < more; i++)
            {
                _decimal += '0';
            }
            string result = SquareInteger(_decimal, baseNumber);

            return(Devision10(result, temp));
        }
Exemple #4
0
        public static string DivisionDecimal(string decimal1, string decimal2, int accuracy)
        {
            int need1 = CalculateUtilities.ConvertDecimal(ref decimal1);
            int need2 = CalculateUtilities.ConvertDecimal(ref decimal2);

            if (need1 > need2)
            {
                int temp = need1 - need2;
                for (int i = 0; i < temp; i++)
                {
                    decimal2 += '0';
                }
            }
            else
            {
                int temp = need2 - need1;
                for (int i = 0; i < temp; i++)
                {
                    decimal1 += '0';
                }
            }
            string remainder = "";
            string result    = DivisionInteger(decimal1, decimal2, out remainder);

            if (accuracy == 0 || remainder == "0")
            {
                return(result);
            }
            for (int i = 0; i < accuracy; i++)
            {
                remainder += '0';
            }
            string sTemp = DivisionInteger(remainder, decimal2);

            while (sTemp.Length < accuracy)
            {
                sTemp = '0' + sTemp;
            }
            return(result + '.' + sTemp);
        }