.net 保留小数点后n位(不四舍五入)

//四舍五入方法

public static class DecimalHelper
        {
            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);
            }
        }

  decimal d= TotalPoint / poingMoney;
                        DecimalHelper.CutDecimalWithN(d, 2);//小数点后两位
                        userinfo.RechangeMoney = d;

猜你喜欢

转载自www.cnblogs.com/zttb/p/9341364.html