C# wpf calculator -


i'm making calculator exception when try make calculation decimal number. there wrong with sum1 += double.parse(nument.text); i'm bit lost now:p

    public partial class mainwindow : window {     double sum1 = 0;     double sum2 = 0;     string dotsign = "";     bool plusbuttonclicked = false;     bool subbuttonclicked = false;     bool multbuttonclicked = false;     bool divbuttonclicked = false;       public mainwindow()     {         initializecomponent();     }      private void numbervalidationtextbox(object sender, textcompositioneventargs e)     {         regex regex = new regex("[^0-9]+");         e.handled = regex.ismatch(e.text);     }      private void one_click(object sender, routedeventargs e)     {         nument.text += one.content;     }      private void two_click(object sender, routedeventargs e)     {         nument.text += two.content;     }      private void three_click(object sender, routedeventargs e)     {         nument.text += three.content;     }      private void four_click(object sender, routedeventargs e)     {         nument.text += four.content;     }      private void five_click(object sender, routedeventargs e)     {         nument.text += five.content;     }      private void six_click(object sender, routedeventargs e)     {         nument.text += six.content;     }      private void seven_click(object sender, routedeventargs e)     {         nument.text += seven.content;     }      private void eight_click(object sender, routedeventargs e)     {         nument.text += eight.content;     }      private void nine_click(object sender, routedeventargs e)     {         nument.text += nine.content;     }      private void zero_click(object sender, routedeventargs e)     {         nument.text += zero.content;     }      private void add_click(object sender, routedeventargs e)     {          sum1 += double.parse(nument.text);         nument.clear();          plusbuttonclicked = true;         subbuttonclicked = false;         multbuttonclicked = false;         divbuttonclicked = false;     }      private void sub_click(object sender, routedeventargs e)     {         sum1 += double.parse(nument.text);         nument.clear();          plusbuttonclicked = false;         subbuttonclicked = true;         multbuttonclicked = false;         divbuttonclicked = false;     }      private void mult_click(object sender, routedeventargs e)     {         sum1 += double.parse(nument.text);         nument.clear();          plusbuttonclicked = false;         subbuttonclicked = false;         multbuttonclicked = true;         divbuttonclicked = false;     }      private void div_click(object sender, routedeventargs e)     {         sum1 = convert.todouble(dotsign);         sum1 += double.parse(nument.text);         nument.clear();          plusbuttonclicked = false;         subbuttonclicked = false;         multbuttonclicked = false;         divbuttonclicked = true;     }      public void deci_click(object sender, routedeventargs e)     {         double currentinput = nument.text.length;         bool pointfound = false;          /*for (int = 0; < currentinput.length; i++)         {             if (currentinput[i] == '.')                 pointfound = true;          }*/          if (pointfound == false)             nument.text += ".";      }      private void equal_click(object sender, routedeventargs e)     {         if (plusbuttonclicked == true)         {             sum2 = sum1 + double.parse(nument.text);             result.text = sum2.tostring();             sum1 = 0;         }          if (subbuttonclicked == true)         {             sum2 = sum1 - double.parse(nument.text);             result.text = sum2.tostring();             sum1 = 0;         }          if (multbuttonclicked == true)         {             sum2 = sum1 * double.parse(nument.text);             result.text = sum2.tostring();             sum1 = 0;         }          if (divbuttonclicked == true)         {             sum2 = sum1 / double.parse(nument.text);             result.text = sum2.tostring();             sum1 = 0;         }          nument.clear();     }      private void clear_click(object sender, routedeventargs e)     {         nument.clear();         calculations.clear();         result.clear();     }      private void change_click(object sender, routedeventargs e)     {         double signchange = nument.text.length;         signchange = -signchange;         nument.text = signchange.tostring();     }       } } 

double.parse(string)

only 3 possible exceptions double.parse(string), , since doesn't seem played parameter, you're getting formatexception. talking decimal numbers, i'm guessing comes down decimal , groups separators you're using. defaults, think can use '.' decimal separator , ',' or ' ' groups one.

you should consider using double.parse(string, numberstyle) define more precisely separators wish use in calculator.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -