C#之数值

来源:互联网 发布:office word 2016 mac 编辑:程序博客网 时间:2024/05/22 01:57
Math.Ceiling();向上取整
Math.Ceiling()向上取整; d = 4.56789 string res = Math.Ceiling(Convert.ToDecimal(d)).ToString();    res=5
Math.Floor()向下取整 ;string res = Math.Floor(Convert.ToDouble(d)).ToString();     es=4
Math.Round是"就近舍入",当要舍入的是5时与"四舍五入"不同(取偶数),如:
Math.Round(0.5,0)=0 
floor 和 ceiling是math unit 里的函数,使用前要先 Uses Math。
trunc 和 round 是system unit 里的函数,缺省就可以用。
floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124
0 0