错误:用户代码未处理Formatexception。 [英] error:Formatexception was unhandled by user code.

查看:390
本文介绍了错误:用户代码未处理Formatexception。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图将文本框值解析为double但我收到错误System.FormatException未被用户代码处理 - 输入字符串不在一个正确的格式;

这让我抓狂!有人能看出问题是什么吗?



我这样想,< br $>


Hi,

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的值在相应的文本框中,如0.00051368,-15,1.89574224。



我试过double.Tryparse然后我我没有得到例外,但最终只有零'。我知道parse和Tryparse之间的区别。



请有人帮我解决该行中的错误。


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:

0.00051368:-15:1.89574224





因此在第一条Parse线上放置断点,并检查输入。其中一个不是你认为的......



So put a breakpoint on the first Parse line, and examine your inputs. One of them is not what you think it is...


您是否检查了系统的区域设置?可能期待0,123而不是0.123



祝你好运!
Did you check the regional settings of the system? Might be expecting 0,123 instead of 0.123

Good luck!


这篇关于错误:用户代码未处理Formatexception。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆