Kingdee.BOS.MathUtil.Round 十进制四舍五入/双精度数四舍五入

#region 程序集 Kingdee.BOS, Version=7.7.2297.10, Culture=neutral, PublicKeyToken=null
// D:\WorkSpace\SZLS\HANS_CLOUD\K3Cloud\BIN\Kingdee.BOS.dll
// Decompiled with ICSharpCode.Decompiler 6.1.0.5902
#endregion
using System;
namespace Kingdee.BOS
{
//
// 摘要:
// 数学运算工具类
public class MathUtil
{
//
// 摘要:
// 四舍五入模式,可配置 暂时设置为四舍六入五成双
private static MidpointRounding mode;
//
// 摘要:
// 十进制四舍五入
public static decimal Round(decimal value, int decimals = 0, RoundMode mode = RoundMode.AwayFromZero)
{
if (mode == RoundMode.AwayFromZero || mode == RoundMode.ToEven)
{
MidpointRounding midpointRounding = MidpointRounding.AwayFromZero;
if (mode == RoundMode.ToEven)
{
midpointRounding = MidpointRounding.ToEven;
}
return Math.Round(value, decimals, midpointRounding);
}
decimal d = Convert.ToDecimal(Math.Pow(10.0, decimals));
decimal d2 = value * d;
d2 = ((mode != RoundMode.Carry) ? Math.Truncate(d2) : Math.Ceiling(d2));
return d2 / d;
}
//
// 摘要:
Kingdee.BOS.MathUtil.Round 十进制四舍五入/双精度数四舍五入
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



