当前位置: 代码迷 >> 综合 >> 取整函数 ceil、floor、round
  详细解决方案

取整函数 ceil、floor、round

热度:57   发布时间:2024-01-09 11:17:42.0

在这里插入图片描述
f l o o r ( ) floor() floor():地面,地板,所以函数向下取整,即最接近 x x x的较小整数


在这里插入图片描述
c e i l ( ) ceil() ceil():天花板,所以函数向上取整,即最接近 x x x的较大整数


r o u n d ( ) round() round():大约,环绕,所以函数四舍五入

在这里插入图片描述

double round(double r) {return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
  相关解决方案