Click here to Skip to main content
15,312,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to parse textbox value into double but i am getting error "System.FormatException was unhandled by user code - Input string was not in a correct format;
This is driving me crazy! Can anyone see what the problem is?"

I am trying like this,

double a= double.Parse(txtcoeffciantA.Text);
           double b = double.Parse(txtcoeffciantB.Text);
           double c= double.Parse(txtcoeffciantC.Text);

i have the values in corresponding textbox like 0.00051368, -15, 1.89574224.

I have tried with "double.Tryparse" then i am not getting exception but endup with all zero's. i know the difference between parse and Tryparse.

Please someone help me what is wrong in that line.

I tried exactly your code:
TextBox txtcoeffciantA = new TextBox();
txtcoeffciantA.Text = "0.00051368";
TextBox txtcoeffciantB = new TextBox();
txtcoeffciantB.Text = "-15";
TextBox txtcoeffciantC = new TextBox();
txtcoeffciantC.Text = "1.89574224";
double a = double.Parse(txtcoeffciantA.Text);
double b = double.Parse(txtcoeffciantB.Text);
double c = double.Parse(txtcoeffciantC.Text);
Console.WriteLine("{0}:{1}:{2}", a, b, c);
And it worked exactly as I would expect:

So put a breakpoint on the first Parse line, and examine your inputs. One of them is not what you think it is...
vebi1000 26-Apr-13 3:34am
The problem is system regional settings...i need to put "," instead of ".".Really i don't know this is the problem so i have asked question. Thanks for your suggestion.
OriginalGriff 26-Apr-13 3:42am
If you want to use a specific format, there is also a double.Parse overload which takes a specific culture rather than using the default system setting.
Did you check the regional settings of the system? Might be expecting 0,123 instead of 0.123

Good luck!
vebi1000 26-Apr-13 3:34am
Yes you are right, i have tried as you said it is working. thanks alot,i don't know this will be a problem.
E.F. Nijboer 26-Apr-13 4:34am
You can get the information from System.Globalization.CultureInfo.CurrentCulture.NumberFormat. Check this link for more info:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900