C#winform问题,多个textbox输入数字的计算
try{doublei=int.Parse(jiage1.Text.Trim());doublei2=int.Parse(jiage2.Text.Trim());doub...
try
{
double i = int.Parse(jiage1.Text.Trim());
double i2 = int.Parse(jiage2.Text.Trim());
double i3 = int.Parse(jiage3.Text.Trim());
double i4 = int.Parse(jiage4.Text.Trim());
double i5 = int.Parse(jiage5.Text.Trim());
double i6 = int.Parse(jiage6.Text.Trim());
double i7 = int.Parse(jiage7.Text.Trim());
double i8 = int.Parse(jiage8.Text.Trim());
label5.Text = ((double)(i + i2 + i3 + i4 + i5 + i6 + i7 + i8)).ToString();
}
catch(FormatException ex)
{
MessageBox.Show(ex.Message);
}
加入小数点了计算怎么写?\ 展开
{
double i = int.Parse(jiage1.Text.Trim());
double i2 = int.Parse(jiage2.Text.Trim());
double i3 = int.Parse(jiage3.Text.Trim());
double i4 = int.Parse(jiage4.Text.Trim());
double i5 = int.Parse(jiage5.Text.Trim());
double i6 = int.Parse(jiage6.Text.Trim());
double i7 = int.Parse(jiage7.Text.Trim());
double i8 = int.Parse(jiage8.Text.Trim());
label5.Text = ((double)(i + i2 + i3 + i4 + i5 + i6 + i7 + i8)).ToString();
}
catch(FormatException ex)
{
MessageBox.Show(ex.Message);
}
加入小数点了计算怎么写?\ 展开
4个回答
2013-03-21
展开全部
try
{
double i = double.Parse(jiage1.Text.Trim());
double i2 = double.Parse(jiage2.Text.Trim());
double i3 = double.Parse(jiage3.Text.Trim());
double i4 = double.Parse(jiage4.Text.Trim());
double i5 = double.Parse(jiage5.Text.Trim());
double i6 = double.Parse(jiage6.Text.Trim());
double i7 = double.Parse(jiage7.Text.Trim());
double i8 = double.Parse(jiage8.Text.Trim());
label5.Text = (i + i2 + i3 + i4 + i5 + i6 + i7 + i8).ToString();
}
catch(FormatException ex)
{
MessageBox.Show(ex.Message);
}
这样就行了
{
double i = double.Parse(jiage1.Text.Trim());
double i2 = double.Parse(jiage2.Text.Trim());
double i3 = double.Parse(jiage3.Text.Trim());
double i4 = double.Parse(jiage4.Text.Trim());
double i5 = double.Parse(jiage5.Text.Trim());
double i6 = double.Parse(jiage6.Text.Trim());
double i7 = double.Parse(jiage7.Text.Trim());
double i8 = double.Parse(jiage8.Text.Trim());
label5.Text = (i + i2 + i3 + i4 + i5 + i6 + i7 + i8).ToString();
}
catch(FormatException ex)
{
MessageBox.Show(ex.Message);
}
这样就行了
展开全部
double i = double.Parse(jiage1.Text.Trim());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这段代码本身就有问题 。。 后面int 前面double 会精度丢失的
加入小数点就如楼下所说的
加入小数点就如楼下所说的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int.Parse改成double.Parse
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询