gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:13:15 26 4
gpt4 key购买 nike

我正在做一个应用程序,我需要始终使用 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);
}
}

关于c# - 将 MidpointRounding.AwayFromZero 设置为默认舍入方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com