Example #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));
        }
Example #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));
        }
Example #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);
        }
Example #5
0
        public string BinaryHandler(string element1, string element2, string function)
        {
            element1 = CalculateUtilities.StandardizedDisplay(element1);
            element2 = CalculateUtilities.StandardizedDisplay(element2);
            switch (function)
            {
            case "add":
                return(BinaryOperatorService.AddDecimal(element1, element2));

            case "subtract":
                return(BinaryOperatorService.SubtractDecimal(element1, element2));

            case "mutipilation":
                return(BinaryOperatorService.MutipilationDecimal(element1, element2));

            case "devision":
                return(BinaryOperatorService.DivisionDecimal(element1, element2, 20));

            default:
                throw new Exception();
            }
        }
        public static string Devision10(string number, int n)
        {
            if (n < 0)
            {
                return(Mutipilation10(number, -n));
            }
            if (n == 0)
            {
                return(number);
            }
            int index  = number.IndexOf('.');
            int length = number.Length;

            if (index < 0)
            {
                index = length;
            }
            else
            {
                number = number.Remove(index, 1);
            }
            int _index = index - n;

            if (_index > 0)
            {
                number = number.Insert(_index, ".");
            }
            else if (_index <= 0)
            {
                _index = -_index;
                for (int i = 0; i < _index; i++)
                {
                    number = '0' + number;
                }
                number = "0." + number;
            }
            return(CalculateUtilities.StandardizedDisplay(number));
        }
        public static string Mutipilation10(string number, int n)
        {
            if (n < 0)
            {
                return(Devision10(number, -n));
            }
            if (n == 0)
            {
                return(number);
            }
            int index  = number.IndexOf('.');
            int length = number.Length;

            if (index < 0)
            {
                index = length;
            }
            else
            {
                number = number.Remove(index, 1);
            }
            int _index = index + n;

            if (_index < length)
            {
                number = number.Insert(_index, ".");
            }
            else if (_index > length)
            {
                int temp = _index - length;
                for (int i = 0; i < temp; i++)
                {
                    number += '0';
                }
            }
            return(CalculateUtilities.StandardizedDisplay(number));
        }
Example #8
0
 public string UnaryHandler(string element, string function)
 {
     element = CalculateUtilities.StandardizedDisplay(element);
     if (function.Contains("precent"))
     {
         return(UnaryOperatorService.Devision10(element, 2));
     }
     else if (function.Contains("inverse"))
     {
         return(UnaryOperatorService.InverseNumber(element));
     }
     else if (function.Contains("exponential"))
     {
         return(UnaryOperatorService.ExponentialDecimal(element, function[function.Length - 1] - '0'));
     }
     else if (function.Contains("square"))
     {
         return(UnaryOperatorService.SquareDecimal(element, function[function.Length - 1] - '0', 10));
     }
     else
     {
         throw new Exception();
     }
 }