/// <summary> /// To find the percentage, if other additional operations are applied /// </summary> /// <remarks> /// <para>For operations that do not have a character notation in the expression</para> /// <para>In the case of the " % " operation, the change is that the last number or sequence of operations is replaced with a specific percentage of the rest of the expression</para> /// </remarks> /// <returns> /// The string of the current expression with the percentage found /// </returns> private string ChangeTheSetOfRecentAdditionalOperations(string currentExpression) { int pos; string copiedFragment; StringBuilder stringBuilderCurExpr = CurrentExpressionChange(currentExpression, out pos, out copiedFragment); Calculate calculate = new Calculate(); double number; if (Common.MathSignCheck(currentExpression)) { number = calculate.CalcPercentage(copiedFragment, stringBuilderCurExpr.ToString().Remove(stringBuilderCurExpr.Length - 3, 3)); } else { number = calculate.CalcPercentage(copiedFragment, stringBuilderCurExpr.ToString()); } if (NumberStandardization.NumberCheck(number.ToString())) { stringBuilderCurExpr.Insert(pos, number.ToString()); } else { stringBuilderCurExpr.Insert(pos, ((int)Digits.Zero).ToString()); } return(stringBuilderCurExpr.ToString()); }
/// <summary> /// To change the current expression depending on the pressed operation and the state of the buttons /// </summary> private string NewCurrentExpression() { if (buttonsState.EqualBtnPressed) { buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); return(NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)).ToString())); } else { if (currentData.CurrentExpression != string.Empty) { if (buttonsState.AdditionalOperationBtnPressed) { return(ChangeTheSetOfRecentAdditionalOperations(currentData.CurrentExpression)); } else { return(currentData.CurrentExpression + NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)).ToString())); } } else { return(currentData.CurrentExpression + NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), ((int)Digits.Zero).ToString()).ToString())); } } }