C++常用的取整函数有三个ceil,floor,round
ceil的英文释义:装天花板,装船内格子板;函数功能是向上取整
floor的英文释义:楼层; 地面,地板;函数功能是向下取整
round的英文释义:大约;函数功能是四舍五入
示例:
int _tmain(int argc, _TCHAR* argv[]){ float num = 8.6f; std::cout << num << " 向上取整为: "<< ceil(num) <<std::endl; std::cout << num << " 向下取整为: "<< floor(num) << std::endl; std::cout << num << " 四舍五入为: "<< round(num) << std::endl; getchar(); return 0;}运行结果: