13.7892 数字长度不确定可能是任何数字,保留2为小数不四舍五入就可了 如13.78

解决方案 »

  1.   

    1、
    Math.Round(0.333333, 2);//按照四舍五入的国际标准
    2、
    double dbdata = 0.335333;
    string str1 = String.Format("{0:F}", dbdata);//默认为保留两位
    3、
    float i = 0.333333;
    int j = (int)(i * 100);
    i =  j / 100;
    4、
    decimal.Round(decimal.Parse("0.3333333"), 2)
    5、
    private System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
    float test = 0.333333f;
    nfi.NumberDecimalDigits = 2;
    string result = test.ToString("N", nfi);
    6、
    string result = String.Format("{0:N2}",Convert.ToDecimal("0.333333").ToString());
      

  2.   


                Double d = 13.7892;            String temp = d.ToString();            if (temp.IndexOf('.') + 2 < temp.Length)
                {
                    temp = temp.Substring(0, temp.IndexOf('.') + 3);
                }
                Console.WriteLine(temp);
      

  3.   

    string result = Regex.Match("13.7892",@"\d+(\.\d{1,2})?").Value;
      

  4.   

    现成的 函数估计没有.. 自己判断截取吧。。 easy.
      

  5.   

    更正:            Double d = 13.7892;            String temp = d.ToString();            if (temp.IndexOf('.') > -1 && temp.IndexOf('.') + 2 < temp.Length)
                {
                    temp = temp.Substring(0, temp.IndexOf('.') + 3);
                }
                Console.WriteLine(temp);
      

  6.   

    decimal d = 13.7892m;
    d = Math.Round(d - 0.005m, 2);
      

  7.   

    double x= 0.12345;
    x= x- 0.005;
    MessageBox.Show(x.ToString("0.00"));double y = x % 0.01;
    double z = x - y;