int b = (int)a; //不四舍五入运算方法1 int c = Convert.ToInt32(a); //四舍五入运算方法1 double d = System.Math.Floor(a); //不四舍五入运算方法2:返回小于或等于指定双精度浮点数的最大整数。 double f = System.Math.Round(a); //四舍五入运算方法2:将双精度浮点值舍入为最接近的整数。 double i = System.Math.Round(a, 2);//保留2位小数方法1:按照四舍五入的国际标准 double j = i % (int)a; //取小数部分方法1 string g = a.ToString("f2");//保留2位小数方法2 string h ="0"+ g.Substring(g.IndexOf('.')); //取小数部分方法2
Response.Write("a:"+a+"<br />"); Response.Write("b:"+ b +"<br />"); Response.Write("c:"+ c +"<br />"); Response.Write("d:"+ d +"<br />"); Response.Write("f:"+ f +"<br />"); Response.Write("g:"+ g +"<br />"); Response.Write("h:"+ h +"<br />"); Response.Write("i:"+ i +"<br />"); Response.Write("j:"+ j +"<br />");