用sivlerlight做动画和特效时经常会用到Math类,总结一下。
参考:http://www.cnblogs.com/del/archive/2011/01/03/1924746.html
//返回数字的绝对值 Console.WriteLine(Math.Abs(-10)); //向上进位取整 Console.WriteLine(Math.Ceiling(32.1));//33 Console.WriteLine(Math.Ceiling(32.0));//32 Console.WriteLine(Math.Ceiling(-32.1));//32 Console.WriteLine(Math.Ceiling((decimal)(7 + 9) / 10)); //向下舍位取整 Console.WriteLine(Math.Floor(32.9));//32 Console.WriteLine(Math.Floor(32.0));//32 Console.WriteLine(Math.Floor(-32.5)); //-33 Console.WriteLine(Math.Max(1, 9));//9 Console.WriteLine(Math.Min(1, 9));//1 Console.WriteLine(Math.Pow(2, 3));//8 //取指定位数的小数 四舍六入五考虑,五后非零就进一,五后皆零看奇偶,五前为偶应舍 去,五前为奇要进一 Math.Round(0.5); // 0 Math.Round(1.5); // 2 Math.Round(2.5); // 2 Math.Round(3.5); // 4 Math.Round(-0.5); // 0 Math.Round(-1.5); //-2 Math.Round(-2.5); //-2 Math.Round(-3.5); //-4 Math.Round(0.5, MidpointRounding.AwayFromZero); // 1 Math.Round(1.5, MidpointRounding.AwayFromZero); // 2 Math.Round(2.5, MidpointRounding.AwayFromZero); // 3 Math.Round(3.5, MidpointRounding.AwayFromZero); // 4 Math.Round(-0.5, MidpointRounding.AwayFromZero); //-1 Math.Round(-1.5, MidpointRounding.AwayFromZero); //-2 Math.Round(-2.5, MidpointRounding.AwayFromZero); //-3 Math.Round(-3.5, MidpointRounding.AwayFromZero); //-4 Console.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);//正无穷大