2012-02-05 84 views
0

對不起,這個無趣的問題,但我無法弄清楚。在silverlight應用程序中使用c#我希望13/8的結果是1.63。我可以達到1.62或1.625,但不是所需的1.63。請人人友善地向我展示如何?非常感謝。在Silverlight中舍入

+0

http://stackoverflow.com/questions/921180/how-can-i-ensure-that-a-division-of-integers-is-always-rounded-up – jordanhill123 2012-02-05 10:04:36

回答

0

用途:

var rounded = Math.Round(number, 2, MidpointRounding.AwayFromZero); 

你的問題是,在默認情況下,Math.Round()使用「銀行家舍入」,在案件回合數爲中途兩個人(如1.625)則向最接近甚至四捨五入之間數字(例如1.62

+0

我試過但它會在這裏產生錯誤'無法訪問內部枚舉'Midpointrounding'。 – user995689 2012-02-05 10:08:20

+1

哦,是的,我忘了你在silverlight ...看看這裏:http://anderly.com/2009/08/08/silverlight-midpoint-rounding-solution/ – digEmAll 2012-02-05 10:14:17