C# Math.Floor(), Math.Round,Math.Ceiling()

Math.Floor()

取整数部分,即去小数:

Math.Floor(0.0) //0
Math.Floor(0.1) //0
Math.Floor(0.2) //0
Math.Floor(0.3) //0
Math.Floor(0.4) //0
Math.Floor(0.5) //0
Math.Floor(0.6) //0
Math.Floor(0.7) //0
Math.Floor(0.8) //0
Math.Floor(0.9) //0

Math.Round()

C#中Round()函数是四舍六入取五取偶

Math.Round(0.0) //0
Math.Round(0.1) //0
Math.Round(0.2) //0
Math.Round(0.3) //0
Math.Round(0.4) //0
Math.Round(0.6) //1
Math.Round(0.7) //1
Math.Round(0.8) //1
Math.Round(0.9) //1
Math.Round(1.0) //1

Math.Round(0.5) //0
Math.Round(1.5) //2
Math.Round(2.5) //2
Math.Round(3.5) //4
Math.Round(4.5) //4
Math.Round(5.5) //6
Math.Round(6.5) //6

Math.Ceiling()

向上取整

Math.Ceiling(0.0) //0
Math.Ceiling(0.1) //1
Math.Ceiling(0.2) //1
Math.Ceiling(0.3) //1
Math.Ceiling(0.4) //1
Math.Ceiling(0.5) //1
Math.Ceiling(0.6) //1
Math.Ceiling(0.7) //1
Math.Ceiling(0.8) //1
Math.Ceiling(0.9) //1
Math.Ceiling(1.0) //1
Math.Ceiling(1.1) //2

你可能感兴趣的:(C#,C#,Ceiling,Round,Floor)