Dotcpp  >  编程教程  >  math.h头文件  >  C语言floor()函数:向下舍入

C语言floor()函数:向下舍入

点击打开在线编译器,边学边练

函数名: floor

头文件:<math.h>

函数原型: double floor(double x);

功 能: 向下舍入

参数:double x  为要操作的双精度值

返回值:返回 <=x 的用双精度浮点数表示的最大整数。


程序例:  求浮点数number的向下取整,并将结果输出

#include<stdio.h>

#include<math.h>

int main(void){

   double number = 123.54;

   double down, up;

   down = floor(number);

   up = ceil(number);

   printf("original number %10.2lf\n", number);

   printf("number rounded down %10.2lf\n",   down);

   printf("number rounded up %10.2lf\n", up);

   return 0;

}


运行结果:

original number     123.54
number rounded down     123.00
number rounded up     124.00



本文固定URL:https://www.dotcpp.com/course/471

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)