.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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM