-
ceil
鎖定
ceil基本介紹
函數名: ceil
用 法: double ceil(double x);
頭文件:math.h
説明:float ceil ( float value )
返回不小於 value 的下一個整數,ceil() 返回不小於value的最小整數,value 如果有小數部分則進一位。ceil() 返回的類型仍然是 float,因為 float 值的範圍通常比 integer 要小。
[2]
ceil相關函數
函數名:Floor
用 法: double Floor(double x);
ceil相關實例
C/C++程序實例
#include<stdio.h> #include<math.h> int main(void) { double number=123.45; double down,up; down=floor(number); up=ceil(number); printf("originalnumber = %5.2lf\n",number); printf("numberroundeddown = %5.2lf\n",down); printf("numberroundedup = %5.2lf\n",up); return 0; }
運行結果:
originalnumber = 123.45 numberroundeddown = 123.00 numberroundedup = 124.00
javascript實例
<html> <body> <scripttype="text/javascript"> document.write(Math.ceil(0.60)+"<br/>") document.write(Math.ceil(0.40)+"<br/>") document.write(Math.ceil(5)+"<br/>") document.write(Math.ceil(5.1)+"<br/>") document.write(Math.ceil(-5.1)+"<br/>") document.write(Math.ceil(-5.9)) </script> </body> </html>
php程序實例一
<?php echo(ceil(0.60); echo(ceil(0.40); echo(ceil(5); echo(ceil(5.1); echo(ceil(-5.1); echo(ceil(-5.9)); ?>
輸出:
1 1 5 6 -5 -5
php程序實例二
<?php echo ceil(4.3);//5 echo ceil(9.999);//10 ?>