加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 将MidpointRounding.AwayFromZero设置为默认的舍入方法

发布时间:2020-12-16 01:52:54 所属栏目:百科 来源:网络整理
导读:我正在做一个应用程序,我需要使用MidpointRounding.AwayFromZero对数字进行舍入,但每次进行舍入时我都要编写以下语句 Math.Round(xxx,ddd,MidpointRounding.AwayFromZero); 有没有办法将MidpointRounding.AwayFromZero设置为方法Math.Round(…)的默认方式?
我正在做一个应用程序,我需要使用MidpointRounding.AwayFromZero对数字进行舍入,但每次进行舍入时我都要编写以下语句

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

有没有办法将MidpointRounding.AwayFromZero设置为方法Math.Round(…)的默认方式?

解决方法

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

不,没有.

但是你可以编写一个使用MidpointRounding.AwayFromZero的辅助方法.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读