如何舍入小数答案 [英] how to round of decimal answer
本文介绍了如何舍入小数答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何回答
How to round of answer
decimal a = decimal.Parse(Label20.Text);
decimal b = decimal.Parse(Label15.Text);
decimal c = b - a;
Label22.Text = c.ToString();
推荐答案
Math.Round(Convert.ToDecimal(Label20.Text)), 2);
或
OR
double doubleNumber;
doubleNumber= 17843.1234;
doubleNumber.ToString("F2",CultureInfo.InvariantCulture));
// Displays 17843.12
>
请参阅我对该问题的评论。我看不到你需要四舍五入的地方。相反,您需要正确的字符串格式,以获得舍入值。请参阅:
https:// msdn .microsoft.com / zh-CN / library / fzeeb5cd%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx [ ^ ]。
-SA
Please see my comment to the question. I don't see where you need rounding. Rather, you need proper string formatting, to get rounded value. Please see:
https://msdn.microsoft.com/en-us/library/fzeeb5cd%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx[^].
—SA
阅读文档:Decimal.Round Method(Decimal) [ ^ ]
这篇关于如何舍入小数答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文