C++ cmath ceil() 函数
示例
将数字向上取整到最接近的整数:
cout << ceil(0.60);
cout << ceil(0.40);
cout << ceil(5);
cout << ceil(5.1);
cout << ceil(-5.1);
cout << ceil(-5.9);
亲自试一试 »
定义和用法
ceil() 函数将数字向上取整到最接近的整数。
ceil() 函数定义在 <cmath> 头文件中。
提示: 要将数字向下取整到最接近的整数,请查看 floor() 函数。
提示: 要将数字向上或向下取整到最接近的整数,请查看 round() 函数。
语法
以下选项之一:
ceil(double number);
ceil(float number);
参数值
| 参数 | 描述 |
|---|---|
| number | 必填。指定一个数字。如果该数字为整数类型,则会被视为 double 类型。 |
技术细节
| 返回值: | 返回一个 float 值(如果参数是 float 类型)或 double 值(在其他情况下),表示大于或等于该数的最接近整数。 |
|---|

