[转]c#保留小数点后位数的方法

 1             Double dValue = 95.12345;
 2 
 3             int iValue = 10000;
 4             string strValue = "95.12345";
 5             string result = "";
 6 
 7             result = Convert.ToDouble(dValue).ToString("0.00");//保留小数点后两位,结果为95.12
 8             result = Convert.ToDouble(iValue).ToString("0.00");//10000.00 
 9             result = Convert.ToDouble(strValue).ToString("0.00");//95.12
10 
11             result = Convert.ToDouble(dValue).ToString("P");//得到小数点后2位的百分比,自动 加上%号;//9512.35%
12             result = Convert.ToDouble(strValue).ToString("f4");//保留小数点后4位;  //95.1235
13             //要注意的一点是 Convert.ToDouble一定要是这种双精度的,不然会报错。
原文地址:https://www.cnblogs.com/seasons1987/p/3020060.html