如何将字符串值除以另一个字符串值,每个字符串值均包含数字值
问题描述:
如何使我的标签正确显示NumericUpDown1
/NumericUpDown2
?如何将字符串值除以另一个字符串值,每个字符串值均包含数字值
这里是我有什么
label6.Text = Convert.ToString(NumericUpDown1.Value/NumericUpDown2.Value);
我也曾尝试
label6.text = NumericUpDown1.value/NumericUpDown2.value
,并得到一个错误说
不能隐Convery等等等等成字节
一个后我开始我的项目它崩溃(我所以只要把它当作我的项目打开它尝试显示NumUD1
/NumUD2
...
答
在最简单的术语:
decimal d = (NumericUpDown1.value/NumericUpDown2.value);
stringVal = System.Convert.ToString(d);
label6.text = stringVal;
或者你可以创建的NumericUpDown的子类,并覆盖ParseValue方法(如图here):
public class MyNumericUpDown : NumericUpDown {
protected override double ParseValue(string text)
{
// Change text to whatever you want
string newText = FixText(text);
// Call base implementation.
base.ParseValue(newText);
}
private static string FixText(string inputText) {
// DO YOUR STUFF HERE.
}
}
答
值转换为int
,然后进行分割,然后通过转换为string
它分配给label6.Text
:
label6.Text = (Convert.ToInt32(NumericUpDown1.Value.ToString())/Convert.ToInt32(NumericUpDown1.Value.ToString())).ToString();
+0
得到这个错误 - http://gyazo.com/cc45199111e4455fec57a670692dc228 –
+0
@JacobReid:那是因为我忘了在'Value'后面删除'()'。现在我已经更新了我的答案。 –
对不起对于具有误导性的评论,我的意思是我想的标签,以显示NumericUpDown1中划分BY NumericUpDown2结果:) –
我的更新回答,我没有IDE,所以它只是从内存中。我不是一个C#程序员... – Woodstock