C++ cmath ceil() 函数
定义和用法
ceil()
函数将数向上舍入到最近的整数。
ceil()
函数定义在 <cmath>
头文件中。
提示:若要将一个数向下舍入到最近的整数,请使用 floor()
函数。
提示:若要将一个数向任意方向舍入到最近的整数,请使用 round()
函数。
实例
将数字向上舍入到最近的整数:
cout << ceil(0.60); cout << ceil(0.40); cout << ceil(5); cout << ceil(5.1); cout << ceil(-5.1); cout << ceil(-5.9);
语法
以下之一:
ceil(double number);
ceil(float number);
参数
参数 | 描述 |
---|---|
number |
必需。指定一个数。 如果该数为整数类型,则将被视为 |
技术细节
返回: |
如果参数为 在其他情况下,返回 |
---|