Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting MidpointRounding.AwayFromZero as the default rounding method

Tags:

c#

I'm doing an app and I need to round the numbers ALWAYS using the MidpointRounding.AwayFromZero but every time I do the rounding I've to write the following statement

Math.Round(xxx, ddd, MidpointRounding.AwayFromZero);

Is there a way to set the MidpointRounding.AwayFromZero to the default way to the method Math.Round(...)?

like image 765
vcRobe Avatar asked Oct 24 '25 18:10

vcRobe


1 Answers

Is there a way to set the MidpointRounding.AwayFromZero to the default way to the method Math.Round(...)?

No, there isn't.

But you can write a helper method that you use everywhere which uses MidpointRounding.AwayFromZero.

public static class MathHelper
{
  public static double Round(double value, int digits)
  {
    return Math.Round(value, digits, MidpointRounding.AwayFromZero);
  }
}
like image 186
Oded Avatar answered Oct 27 '25 07:10

Oded