Math 類的方法概要

來源:互聯網
上載者:User

用sivlerlight做動畫和特效時經常會用到Math類,總結一下。
參考:http://www.cnblogs.com/del/archive/2011/01/03/1924746.html

//返回數位絕對值Console.WriteLine(Math.Abs(-10));//向上進位取整Console.WriteLine(Math.Ceiling(32.1));//33Console.WriteLine(Math.Ceiling(32.0));//32Console.WriteLine(Math.Ceiling(-32.1));//32Console.WriteLine(Math.Ceiling((decimal)(7 + 9) / 10));//向下舍位取整Console.WriteLine(Math.Floor(32.9));//32Console.WriteLine(Math.Floor(32.0));//32Console.WriteLine(Math.Floor(-32.5));       //-33Console.WriteLine(Math.Max(1, 9));//9Console.WriteLine(Math.Min(1, 9));//1Console.WriteLine(Math.Pow(2, 3));//8//取指定位元的小數 四捨六入五考慮,五後非零就進一,五後皆零看奇偶,五前為偶應舍 去,五前為奇要進一Math.Round(0.5);  // 0Math.Round(1.5);  // 2Math.Round(2.5);  // 2Math.Round(3.5);  // 4Math.Round(-0.5); // 0Math.Round(-1.5); //-2Math.Round(-2.5); //-2Math.Round(-3.5); //-4Math.Round(0.5, MidpointRounding.AwayFromZero);  // 1Math.Round(1.5, MidpointRounding.AwayFromZero);  // 2 Math.Round(2.5, MidpointRounding.AwayFromZero);  // 3Math.Round(3.5, MidpointRounding.AwayFromZero);  // 4 Math.Round(-0.5, MidpointRounding.AwayFromZero); //-1Math.Round(-1.5, MidpointRounding.AwayFromZero); //-2Math.Round(-2.5, MidpointRounding.AwayFromZero); //-3Math.Round(-3.5, MidpointRounding.AwayFromZero); //-4Console.WriteLine(Math.Round(3.4452, 2));//3.45 Console.WriteLine(Math.Round(3.4552, 2));//3.46;Console.WriteLine(Math.Round(3.4652, 2));//3.47;Console.WriteLine(System.Double.NaN);//非數字Console.WriteLine(System.Double.NegativeInfinity);//負無窮大Console.WriteLine(System.Double.PositiveInfinity);//正無窮大

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.