C# 代码实现进位、舍位
//调用例子
decimal a = (decimal)1.23456;
var r1 = JinWei(a,2);
var r2 = SheWei(a,2);
/// <summary>
/// 进位
/// </summary>
/// <param name="Num">数值</param>
/// <param name="ws">保留小数位数</param>
/// <returns></returns>
public decimal JinWei(decimal Num, int ws=0)
{
int s=Convert.ToInt32(Math.Pow(10,ws));
decimal NewNum=Math.Ceiling(Num*s);
return NewNum/s;
}
/// <summary>
/// 舍位
/// </summary>
/// <param name="Num">数值</param>
/// <param name="ws">保留小数位数</param>
/// <returns></returns>
public decimal SheWei(decimal Num, int ws=0)
{
int s = Convert.ToInt32(Math.Pow(10, ws));
decimal NewNum = Math.Floor(Num * s);
return NewNum / s;
}
C# 代码实现进位、舍位
本文2024-09-16 17:16:51发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14688.html