我想将 double 四舍五入为整数。
例如,
double a=0.4, b=0.5;
我想把它们都改成整数。
这样
int aa=0, bb=1;
aa
来自a
,bb
来自b
。
有什么公式可以做到这一点?
最佳答案
使用Math.Ceiling
总结
Math.Ceiling(0.5); // 1
使用Math.Round
只是圆
Math.Round(0.5, MidpointRounding.AwayFromZero); // 1
和Math.Floor
向下舍入
Math.Floor(0.5); // 0
关于c# - 如何将值 C# 舍入到最接近的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3920553/