C#取整函数Math.RoundMath.Ceiling和Math.Floor
Posted 沙耶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#取整函数Math.RoundMath.Ceiling和Math.Floor相关的知识,希望对你有一定的参考价值。
1.Math.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.5) //0
Math.Round(0.6) //1
Math.Round(0.7) //1
Math.Round(0.8) //1
Math.Round(0.9) //1
Math.Round(0.1) //0
Math.Round(0.2) //0
Math.Round(0.3) //0
Math.Round(0.4) //0
Math.Round(0.5) //0
Math.Round(0.6) //1
Math.Round(0.7) //1
Math.Round(0.8) //1
Math.Round(0.9) //1
说明:对于1.5,因要返回偶数,所以结果为2。
2.Math.Ceiling:只要有小数都加1
引用内容
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(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
说明:例如在分页算法中计算分页数很有用。
3.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.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
以上是关于C#取整函数Math.RoundMath.Ceiling和Math.Floor的主要内容,如果未能解决你的问题,请参考以下文章
C#取整函数Math.RoundMath.Ceiling和Math.Floor