C/C++取整函数

本文链接:https://blog.csdn.net/auccy/article/details/85240674
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;
}
运行结果:


————————————————
版权声明:本文为CSDN博主「auccy」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/auccy/article/details/85240674

猜你喜欢

转载自www.cnblogs.com/rb258/p/11511485.html