Exemple #1
0
        private bool СheckNumber(ref numberСharacteristic number)
        {
            number.value.Replace('.', ',');
            number.value.Replace(" ", "");
            if (!Decimal.TryParse(number.value.ToString(), out number.decimalValue))
            {
                return(false);
            }
            int k = 0;

            for (int i = number.value.Length - 1; i >= 0; i--)
            {
                if (k <= 2 && (number.value[i] == ',' || number.value[i] == '.'))
                {
                    number.point_position = k;
                    return(true);
                }
                else if (k > 2 && (number.value[i] == ',' || number.value[i] == '.'))
                {
                    number.point_position = -1;
                    return(false);
                }
                k++;
            }
            number.point_position = 0;
            return(true);
        }
Exemple #2
0
        public string Сalculate(numberСharacteristic fNumber, numberСharacteristic sNumber, int operationNumber)
        {
            StringBuilder result = new StringBuilder();

            switch (operationNumber)
            {
            case 0:
                result.Append(Addition(fNumber, sNumber));
                break;

            case 1:
                result.Append(Subtraction(fNumber, sNumber));
                break;

            case 2:
                result.Append(Multiply(fNumber, sNumber));
                decimal resultNumber = Math.Round(Decimal.Parse(result.ToString()), 2, 0);
                result.Length = 0;
                result.Append(resultNumber);
                break;

            case 3:
                result.Append(Divide(fNumber, sNumber));
                decimal resNumber = Math.Round(Decimal.Parse(result.ToString()), 2, 0);
                result.Length = 0;
                result.Append(resNumber);
                fNumber.point_position = FormatResultDivide(result);
                sNumber.point_position = 0;
                break;

            default:
                break;
            }
            return(FormatResult(result, fNumber.point_position, sNumber.point_position).ToString());
        }
Exemple #3
0
        private StringBuilder Divide(numberСharacteristic fNumber, numberСharacteristic sNumber)
        {
            StringBuilder resultNumber = new StringBuilder();
            decimal       firstNumber  = Decimal.Parse(fNumber.value.ToString());
            decimal       secondNumber = Decimal.Parse(sNumber.value.ToString());

            return(resultNumber.Append(Decimal.Divide(firstNumber, secondNumber)));
        }
Exemple #4
0
        private StringBuilder Subtraction(numberСharacteristic fNumber, numberСharacteristic sNumber)
        {
            StringBuilder result       = new StringBuilder();
            decimal       firstNumber  = Decimal.Parse(fNumber.value.ToString());
            decimal       secondNumber = Decimal.Parse(sNumber.value.ToString());

            return(result.Append(firstNumber - secondNumber));
        }