C# Double保留小数点后面位数

Double salary1 = 10000.0;
Double salary2 = 10000.12345;
Double salary3 = 10000.1289;
Int salary4 = 10000;
string salary5 = "10000";
string salary6 = "10000.12345";
string salary7 = "10000.1289"

Convert.ToDouble(salary1).ToString("0.00");//保留小数点后两位,结果为10000.00
Convert.ToDouble(salary2).ToString("0.00");//保留小数点后两位,结果为10000.12
Convert.ToDouble(salary3).ToString("0.00");//保留小数点后两位,结果为10000.13
Convert.ToDouble(salary4).ToString("0.00");//保留小数点后两位,结果为10000.00
Convert.ToDouble(salary5).ToString("0.00");//保留小数点后两位,结果为10000.00
Convert.ToDouble(salary6).ToString("0.00");//保留小数点后两位,结果为10000.12
Convert.ToDouble(salary7).ToString("0.00");//保留小数点后两位,结果为10000.13  

 

int a = 90;            
int b = 110;            
string c = (Convert.ToDouble(a) * 100/Convert.ToDouble(b)).ToString("f1");
Console.WriteLine(c);            
Console.ReadLine();

posted @ 2014-08-01 16:08  银河系上的地球  阅读(1240)  评论(0编辑  收藏  举报