Пример #1
0
        /// <summary>
        /// changes signs of the number
        /// </summary>
        private void PlusMinus()
        {
            // nothing to do for zero
            if (DisplayNumber == "0")
            {
                return;
            }

            // convert negative number to positive
            if (DisplayNumber[0] == '-')
            {
                DisplayNumber = DisplayNumber.Remove(0, 1);
            }
            // convert positive number to negative
            else
            {
                DisplayNumber = "-" + DisplayNumber;
            }
        }
Пример #2
0
        /// <summary>
        /// add number character to number string (DisplayNumber)
        /// </summary>
        /// <param name="sender">the number or symbol entered by user</param>
        /// <returns>DisplayNumber</returns>
        protected void NumberAdd(string sender)
        {
            // start a new equation
            if (endOfEquation)
            {
                endOfEquation = false;
            }

            // if previous entry was an operator, reset the number string
            if (numberProcessing)
            {
                // change of signs is an exception
                if (sender != "+/-")
                {
                    DisplayNumber = "";
                }

                numberProcessing = false;
                if (history[histIndex].GetOperSize() == 0)
                {
                    Equation = "";
                }
            }

            // change signs of the number
            if (sender == "+/-")
            {
                PlusMinus();
            }
            // clear number string and equation
            else if (sender == "C")
            {
                DisplayNumber = "0";
                Equation      = "";
                history[histIndex].Clear();
            }
            // delete one character in number string
            else if (sender == "B")
            {
                if (DisplayNumber.Length > 0)
                {
                    DisplayNumber = DisplayNumber.Remove(DisplayNumber.Length - 1);
                }

                if (DisplayNumber == "")
                {
                    DisplayNumber = "0";
                }
            }
            // add the new number character to the number string
            else
            {
                // if there is only "0" in the number string, remove it first
                if (DisplayNumber == "0" && sender != ".")
                {
                    DisplayNumber = "";
                }

                // if there is already a decimal point, do not add another
                if (!(sender == "." && DisplayNumber.Contains('.')))
                {
                    DisplayNumber += sender;
                }
            }
        }