[英]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.