C++ cmath自带3种方法:
floor()//向上取整floor(10.5) = 10 floor(-10.5) = -11
ceil()//向上取整 ceil(10.5) = 11 ceil(-10.5) =-10
round()//四舍五入round(10.5)=11 round(10.4)=10 round(-2.1)=-2 round(-2.5)=-3
实现原理如下:
int round(double input)
{
if (input >= 0.0)
{
return int(input + 0.5);
}
else
{
return int(input - 0.5);
}
}
&spm=1001.2101.3001.5002&articleId=80139267&d=1&t=3&u=82f8a8a10d4142c8940b51f738375bfc)
1049

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



