c# 让double保留两位小数

1、Math.Round(0.333333,2);//按照四舍五入的国际标准
2、
    double dbdata=0.335333;
    string str1=String.Format("{0:F}",dbdata);//默认为保留两位

   还有一个类似的方法,但是不提倡:
   double d1 = 0.335333;
   string d2 = d1.ToString("0.00");   // string d3 = d1.ToString("f2");

 d2="0.33"



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());

文章来源地址:https://www.cnblogs.com/felix-wang/p/6564438.html

猜你喜欢

转载自blog.csdn.net/ido1ok/article/details/80816479