将MidpointRounding.AwayFromZero设置为默认的四舍五入方法

4

我正在开发一个应用程序,需要始终使用MidpointRounding.AwayFromZero进行四舍五入,但每次进行四舍五入时,我都需要编写以下语句:

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

有没���一种方法可以将MidpointRounding.AwayFromZero设置为方法Math.Round(...)的默认方式?
1个回答

7

有没有一种方法可以将MidpointRounding.AwayFromZero设置为Math.Round(...)方法的默认方式?

没有这种方法。

但是你可以编写一个帮助方法,然后在你的代码中到处使用它,该方法使用MidpointRounding.AwayFromZero。

public static class MathHelper
{
  public static double Round(double value, int digits)
  {
    return Math.Round(value, digits, MidpointRounding.AwayFromZero);
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接