C Math ceil() 函数
定义和用法
ceil() 函数将一个数向上舍入到最近的整数。
ceil() 函数定义在 <math.h> 头文件中。
提示:若要将一个数向下舍入到最近的整数,请使用 floor() 函数。
提示:若要将一个数向任意方向舍入到最近的整数,请使用 round() 函数。
实例
将数字向上舍入到最近的整数:
printf("%f", ceil(0.60));
printf("%f", ceil(0.40));
printf("%f", ceil(5));
printf("%f", ceil(5.1));
printf("%f", ceil(-5.1));
printf("%f", ceil(-5.9));
语法
ceil(double number);
参数
| 参数 | 描述 |
|---|---|
| number | 必需。指定一个数。 |
技术细节
| 返回: | double 类型的值,表示大于或等于指定数的最近整数。 |
|---|
相关页面
教程:C 函数
教程:C 数学函数