Math.Round是"就近舍入",当要舍入的是5时与"四舍五入"不同(取偶数),如:
Math.Round(0.5,0)=0
Math.Round(1.5,0)=2
Math.Round(2.5,0)=2
Math.Round(3.5,0)=4
....
Math.Ceiling(3.1)=4;
Math.Floor(3.9)=3;
取天板值与地板值,与"四舍五入"无关。
其实Floor的结果与(int)相同,因此也可以这样写Math.Floor((double)2/3+0.5)
Math.Round(0.5,0)=0
Math.Round(1.5,0)=2
Math.Round(2.5,0)=2
Math.Round(3.5,0)=4
....
Math.Ceiling(3.1)=4;
Math.Floor(3.9)=3;
取天板值与地板值,与"四舍五入"无关。
其实Floor的结果与(int)相同,因此也可以这样写Math.Floor((double)2/3+0.5)
本文详细解释了Math.Round、Math.Ceiling与Math.Floor等数学函数的使用方式,并着重阐述了Math.Round在处理小数点后5的情况时所采用的就近舍入到偶数规则。
1878

被折叠的 条评论
为什么被折叠?



