#region 计算小数位的,不进行四舍五入
/// <summary>
/// 计算小数位的,不进行四舍五入
/// </summary>
/// <param name="d">数据</param>
/// <param name="n">小数位数</param>
/// <returns></returns>
public static decimal CutDecimalWithN(decimal d, int n)
{
string strDecimal = d.ToString();
int index = strDecimal.IndexOf(".");
if (index == -1 || strDecimal.Length < index + n + 1)
{
strDecimal = string.Format("{0:F" + n + "}", d);
}
else
{
int length = index;
if (n != 0)
{
length = index + n + 1;
}
strDecimal = strDecimal.Substring(0, length);
}
return Decimal.Parse(strDecimal);
}
#endregion
c#计算小数位,不进行四舍五入
最新推荐文章于 2023-07-22 18:03:37 发布