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;
}
//
// 摘要:
// 双精度数四舍五入
//
// 参数:
// value:
//
// digits:
public static double Round(double value, int digits = 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, digits, midpointRounding);
}
double num = Math.Pow(10.0, digits);
double num2 = value * num;
num2 = ((mode != RoundMode.Carry) ? Math.Truncate(num2) : Math.Ceiling(num2));
return num2 / num;
}
}
}
Kingdee.BOS.MathUtil.Round 十进制四舍五入/双精度数四舍五入
本文2024-09-16 18:38:33发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-23454.html
- 鼎捷EAI整合規範文件V3.1.07 (集團).pdf
- 鼎捷OpenAPI應用場景說明_基礎資料.pdf
- 鼎捷OpenAPI應用場景說明_財務管理.pdf
- 鼎捷T100 API設計器使用手冊T100 APIDesigner(V1.0).docx
- 鼎新e-GoB2雲端ERP B2 線上課程E6-2應付票據整批郵寄 領取.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A4使用者建立權限設定.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程C3會計開帳與會計傳票.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程E6-1應付票據.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A5-1進銷存參數設定(初階篇).pdf
- 鼎新e-GoB2雲端ERP B2 線上課程D2帳款開帳與票據開帳.pdf