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;

  • 相关阅读:
    比赛F-F Perpetuum Mobile
    HDU 1003(A
    C-C Radar Installation 解题报告
    Codeforces 18C C. Stripe
    HDU 4911 Inversion
    分蛋糕(C
    抄书(B
    深入了解Android蓝牙Bluetooth——《基础篇》
    2W 字详解 Redis 集群环境搭建实践
    漫画 | 阿姨,我不想努力了~
  • 原文地址:https://www.cnblogs.com/zttb/p/9341364.html
Copyright © 2011-2022 走看看