學用 ASP.Net 之 System.Math 類

來源:互聯網
上載者:User
成員:
/* 欄位 */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;         //取 
練習:
//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);}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.