2009-09-08 95 views

回答

3

您正在寻找Math.Round方法。

//first param is number to round 
//second param is the accuracy to use in the rounding (number of decimal places) 
Math.Round(i, 2) 
1

使用Math.Round方法:

double i = 0.69999980926513672; 
double result = Math.Round(i, 2); 
13

用途之一:

System.Math.Round (i, 1, MidpointRounding.ToEven); 
System.Math.Round (i, 1, MidpointRounding.AwayFromZero); 

所不同的是它如何处理是等距离的舍入点数(例如,0.65在您的案件既可以去到0.7或0.6)。

这是一个answer我给了另一个持有更多信息的问题。

+1

充分利用您丰富的答案组合+1 – 2009-09-08 06:50:16

+0

正如我的妻子所说,当我全速飞行时,从谈话的角度讲,越少人被迫听我说话,他们似乎变得越快乐:-)所以这可能是最好的保持简短的答案,并参考我的链接更多的大量散文。 – paxdiablo 2009-09-08 06:59:58

3
Console.WriteLine(System.Math.Round(0.69999980926513672d, 1)); 

- 编辑

哇,你眨眼还有其他5个答案!

+0

这是Stack Overflow上最常见的“数学”问题之一。 – 2009-09-08 06:48:10