简体   繁体   English

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

[英]Setting MidpointRounding.AwayFromZero as the default rounding method

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 我正在做一个应用程序,我需要使用MidpointRounding.AwayFromZero对数字进行舍入,但每次进行舍入时我都要编写以下语句

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

Is there a way to set the MidpointRounding.AwayFromZero to the default way to the method Math.Round(...)? 有没有办法将MidpointRounding.AwayFromZero设置为方法Math.Round(...)的默认方式?

Is there a way to set the MidpointRounding.AwayFromZero to the default way to the method Math.Round(...)? 有没有办法将MidpointRounding.AwayFromZero设置为方法Math.Round(...)的默认方式?

No, there isn't. 不,没有。

But you can write a helper method that you use everywhere which uses MidpointRounding.AwayFromZero . 但是你可以编写一个使用MidpointRounding.AwayFromZero的辅助方法。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 舍入 MidpointRounding.ToEven 与 MidpointRounding.AwayFromZero - C# Rounding MidpointRounding.ToEven vs MidpointRounding.AwayFromZero 中点舍入为零 - MidpointRounding.AwayFromZero JavaScript中的Math.round MidPointRounding.AwayFromZero - Math.round MidPointRounding.AwayFromZero in javascript 与Delphi中的MidpointRounding.AwayFromZero相当的Math.Round()是什么? - What is the equivalent of Math.Round() with MidpointRounding.AwayFromZero in Delphi? 使用Math.Round和MidpointRounding.AwayFromZero四舍五入一个数字 - Round a number using Math.Round with MidpointRounding.AwayFromZero Math.Round bug 81.725 MidpointRounding.AwayFromZero = 81.72 - Math.Round bug 81.725 MidpointRounding.AwayFromZero = 81.72 为什么MidpointRounding.AwayFromZero和MidpointRounding.ToEven做同样的事情? - Why does MidpointRounding.AwayFromZero and MidpointRounding.ToEven do the same thing? 使用Math.Round(ReportItems!category.Value,MidpointRounding.AwayFromZero)返回不正确的值 - Using Math.Round(ReportItems!category.Value,MidpointRounding.AwayFromZero) returns incorrect value .NET Math.Round(<double>,<int>,MidpointRounding.AwayFromZero)无法正常工作 - .NET Math.Round(<double>,<int>,MidpointRounding.AwayFromZero) not working correctly 如何使用NET Math.Round( <decimal> , <int> ,MidpointRounding.AwayFromZero) - How to round off correctly with NET Math.Round(<decimal>,<int>,MidpointRounding.AwayFromZero)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM