0

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.

user995689
  • 785
  • 3
  • 13
  • 17

1 Answers1

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
  • 1
    Oh 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