ceil
函数名

函数名: ceil

用 法: double ceil(double x);

功 能: 返回大于或者等于指定表达式的最小整数

头文件:math.h

返回数据类型:double

返回不小于 value 的下一个整数,ceil() 返回不小于value的最小整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要小。

中文名

ceil

用法

double ceil

功能

返回大于等于表达式的最小整数

头文件

math.h

属性

函数

近似函数

Floor

基本介绍

函数名: ceil

用 法: double ceil(double x);

功 能: 返回大于或者等于指定表达式的最小整数

头文件:math.h

说明:float ceil ( float value )

返回不小于 value 的下一个整数,ceil() 返回不小于value的最小整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要小1。

相关函数

函数名:Floor

用 法: double Floor(double x);

功 能: 向下取整,返回x的下一个最小值。

相关实例

C/C++程序实例

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main(void)
  4. {
  5.     double number=123.45;
  6.     double down,up;
  7.     down=floor(number);
  8.     up=ceil(number);
  9.     printf("originalnumber = %5.2lf\n",number);
  10.     printf("numberroundeddown = %5.2lf\n",down);
  11.     printf("numberroundedup = %5.2lf\n",up);
  12.      
  13.     return 0;
  14. }

运行结果:

  1. originalnumber = 123.45
  2. numberroundeddown = 123.00
  3. numberroundedup = 124.00

javascript实例

  1. <html>
  2. <body>
  3. <scripttype="text/javascript">
  4. document.write(Math.ceil(0.60)+"<br/>")
  5. document.write(Math.ceil(0.40)+"<br/>")
  6. document.write(Math.ceil(5)+"<br/>")
  7. document.write(Math.ceil(5.1)+"<br/>")
  8. document.write(Math.ceil(-5.1)+"<br/>")
  9. document.write(Math.ceil(-5.9))
  10. </script>
  11. </body>
  12. </html>

php程序实例一

  1. <?php 
  2. echo(ceil(0.60); 
  3. echo(ceil(0.40); 
  4. echo(ceil(5); 
  5. echo(ceil(5.1); 
  6. echo(ceil(-5.1); 
  7. echo(ceil(-5.9)); 
  8. ?>

输出:

  1. 1 
  2. 1 
  3. 5 
  4. 6 
  5. -5 
  6. -5

php程序实例二

  1. <?php
  2. echo ceil(4.3);//5
  3. echo ceil(9.999);//10
  4. ?>
参考资料

1.《Microsoft Quick C库程序参考手册》 ·吴双, 章立生编译·国防工业出版社·1988

目录
01
摘要
02
基本信息
03
基本介绍
04
相关函数
05
相关实例