C#中的数据转换问题 [英] Data convertion problem in C#

查看:61
本文介绍了C#中的数据转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#windows窗体中有一个文本框。

我正在接受输入。

接下来我要将其转换为double。问题来了。

I have one text box in c# windows form.
I am taking input.
next I want to convert that to double. Here is problem is coming.

double.TryParse(txtdisc.Text, out b);



i调试并看到了什么是实际的来临。在那个文本框中有值,但在那个b中没有值到来。我声明b为double b = 0.00。

所以在b中只有0来了。该怎么做。



我尝试过的事情:



我尝试过在其他方面也像convert.ToDouble和double.Parse但没有用。我只在这里得到这个。其他形式的同一个与其他价值观合作。为什么这样。

现在该做什么。


i debugged and saw what is there actutally coming. In that text box value is there but in that "b" no value is coming.I declared "b" as double b=0.00.
so in "b" only 0 is coming. What to do.

What I have tried:

I tried in other ways also like convert.ToDouble and double.Parse but no use. I am getting this here only. other form same one worked with other values. Why like this.
what to do now.

推荐答案

你可以试试下面的代码 -



Can you try with below piece of code -

double b;
bool IsDoubleValue = double.TryParse(textBox1.Text, out b);

//do whatever you want with this value
var doubleTypeValue = IsDoubleValue ? Convert.ToDouble(textBox1.Text) : 0;


这篇关于C#中的数据转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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