Sorry for such a uninteresting question, but I can't figure it out. Using c# in a silverlight app I want the result of 13/8 to be 1.63. I can get it to 1.62 or 1.625, but not the required 1.63. Would anyone please be kind enough to show me how? Many thanks.
Asked
Active
Viewed 1,247 times
0
-
http://stackoverflow.com/questions/921180/how-can-i-ensure-that-a-division-of-integers-is-always-rounded-up – jordanhill123 Feb 05 '12 at 10:04
1 Answers
0
Use:
var rounded = Math.Round(number, 2, MidpointRounding.AwayFromZero);
Your problem is that by default, Math.Round() use the "banker's rounding" that in case the number to round is halfway between two others (e.g. 1.625) it is rounded toward the nearest even number (e.g. 1.62)
digEmAll
- 56,430
- 9
- 115
- 140
-
I have tried that but it generates the error 'can't access internal enum 'Midpointrounding' here. – user995689 Feb 05 '12 at 10:08
-
1Oh yes, I forgot you're in silverlight... have a look here: http://anderly.com/2009/08/08/silverlight-midpoint-rounding-solution/ – digEmAll Feb 05 '12 at 10:14