#region 金额类型只入不舍
/// <summary>
/// 金额类型只入不舍
/// </summary>
/// <param name="Money">需处理的值</param>
/// <param name="Digit">需处理的位数</param>
/// <returns></returns>
public decimal Rounding(decimal num, int Digit)
{
try
{
string numToString = num.ToString("0.###");
int index = numToString.IndexOf(".");
int length = numToString.Length;
if (index != -1)
{
int decimals = numToString.Substring(index + 1, length - index - 1).Length;//小数点后面的位数
if (decimals > Digit)
{
for (int i = 0; i < Digit; i++)
{
num = num * 10;
}
num = num + 1;
for (int i = 0; i < Digit; i++)
{
num = num / 10;
}
return Math.Round(num, 2, MidpointRounding.AwayFromZero);
}
}
else
{
return Math.Round(num, 2, MidpointRounding.AwayFromZero);
}
return Math.Round(num, 2, MidpointRounding.AwayFromZero);
}
catch
{
return Math.Round(num, 2, MidpointRounding.AwayFromZero);
}
}
#endregion
c#金额类型只入不舍
最新推荐文章于 2022-07-14 15:23:52 发布