public void Execute() { double firstOperand = 0; double secondOperand = 0; try { firstOperand = double.Parse(PrepareToParse(FirstOperand.ToString())); secondOperand = double.Parse(PrepareToParse(SecondOperand.ToString())); } catch (System.FormatException e) { Console.WriteLine(e.Message); } double result = 0; switch (actionOperator) { case "+": { result = operacja.Addition(firstOperand, secondOperand); break; } case "-": { result = operacja.Substraction(firstOperand, secondOperand); break; } case "/": { result = operacja.Division(firstOperand, secondOperand); break; } case "x": { result = operacja.Multiplication(firstOperand, secondOperand); break; } case "%": { result = operacja.Percentage(firstOperand, secondOperand); break; } default: { Result = "0"; break; } } Result = result.ToString().Replace(',', '.'); ResetOperandsToDefault(); ResetIsOperandChosen(); }
public string DisplayOperand() { if (isOperandChosen == false) { return(FirstOperand.ToString()); } else { return(SecondOperand.ToString()); } }
/// <summary> /// Update the display text /// </summary> /// <param name="showResult">Display the result or the current calculation</param> private void UpdateDisplay(bool showResult = false) { if (!showResult) { if (Operation != CalculatorOperation.Unknown) { display.text = string.Format("{0} {1} {2}", FirstOperand, OperationToString(), SecondOperand != 0 ? SecondOperand.ToString() : "").Trim(); } else { display.text = FirstOperand.ToString(); } } else { display.text = Result.ToString(); } }