学用 ASP.Net 之 System.Math 类

成员:


/* 常量字段 */Math.E;             //2.71828182845905Math.PI;            //3.14159265358979/* 静态方法 */Math.Abs;           //绝对值Math.Acos;          //反余弦Math.Asin;          //反正弦Math.Atan;          //反正切Math.Atan2;         //反正切, 两参数Math.BigMul;        //int32 * int32 = int64Math.Ceiling;       //取 >= 的最小整数Math.Cos;           //余弦Math.Cosh;          //双曲余弦Math.DivRem;        //取商和余数Math.Exp;           //求 e 的指定次幂Math.Floor;         //取 <= 的最大整数Math.IEEERemainder; //求余Math.Log;           //自然对数Math.Log10;         //以 10 为底的对数Math.Max;           //取大Math.Min;           //取小Math.Pow;           //求幂Math.Round;         //就近舍入, 可指定精度Math.Sign;          //取符号, 或返回 -1、0、1 Math.Sin;           //正弦Math.Sinh;          //双曲正弦Math.Sqrt;          //平方根Math.Tan;           //正切Math.Tanh;          //双曲正切Math.Truncate;      //取整


练习:


//Truncate()、Floor()、Ceiling()protected void Button1_Click(object sender, EventArgs e){    double n1 = Math.Truncate(Math.PI); // 3    double n2 = Math.Floor(2.5);        // 2    double n3 = Math.Floor(-2.5);       //-3    double n4 = Math.Ceiling(2.5);      // 3    double n5 = Math.Ceiling(-2.5);     //-2    TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5);}//就近舍入(取偶)protected void Button2_Click(object sender, EventArgs e){    double n1 = Math.Round(0.5);  // 0    double n2 = Math.Round(1.5);  // 2    double n3 = Math.Round(2.5);  // 2    double n4 = Math.Round(3.5);  // 4    double n5 = Math.Round(-0.5); // 0    double n6 = Math.Round(-1.5); //-2    double n7 = Math.Round(-2.5); //-2    double n8 = Math.Round(-3.5); //-4    TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6, "\n", n7, "\n", n8);}//四舍五入protected void Button3_Click(object sender, EventArgs e){    double n1 = Math.Round(0.5, MidpointRounding.AwayFromZero);  // 1    double n2 = Math.Round(1.5, MidpointRounding.AwayFromZero);  // 2     double n3 = Math.Round(2.5, MidpointRounding.AwayFromZero);  // 3    double n4 = Math.Round(3.5, MidpointRounding.AwayFromZero);  // 4     double n5 = Math.Round(-0.5, MidpointRounding.AwayFromZero); //-1    double n6 = Math.Round(-1.5, MidpointRounding.AwayFromZero); //-2    double n7 = Math.Round(-2.5, MidpointRounding.AwayFromZero); //-3    double n8 = Math.Round(-3.5, MidpointRounding.AwayFromZero); //-4    TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6, "\n", n7, "\n", n8);}//指定小数位数(0..28)的舍入protected void Button4_Click(object sender, EventArgs e){    double n1 = Math.Round(3.126, 2);  // 3.13    double n2 = Math.Round(3.124, 2);  // 3.12    double n3 = Math.Round(3.125, 2);  // 3.12    double n4 = Math.Round(3.135, 2);  // 3.14    double n5 = Math.Round(3.125, 2, MidpointRounding.AwayFromZero);  // 3.13    double n6 = Math.Round(3.135, 2, MidpointRounding.AwayFromZero);  // 3.14    TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6);}

posted on 2011-01-04 08:14  i617  阅读(953)  评论(0编辑  收藏  举报

导航