zoukankan      html  css  js  c++  java
  • .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;

  • 相关阅读:
    xxx
    cdq分治入门--BZOJ1176: [Balkan2007]Mokia
    cdq分治入门--BZOJ3262: 陌上花开
    本月题量 171122晚-171222午
    cdq分治入门--BZOJ1492: [NOI2007]货币兑换Cash
    NOIP2017游记
    xx
    CF601D:Acyclic Organic Compounds
    LOJ#539. 「LibreOJ NOIP Round #1」旅游路线
    composer常用的一些命令参数说明
  • 原文地址:https://www.cnblogs.com/zttb/p/9341364.html
Copyright © 2011-2022 走看看