函数名: floor
头文件:<math.h>
函数原型: double floor(double x);
功 能: 向下舍入
参数:double x 为要操作的双精度值
返回值:返回 <=x 的用双精度浮点数表示的最大整数。
程序例: 求浮点数number的向下取整,并将结果输出
#include<stdio.h>#include<math.h>intmain(void){doublenumber=123.54;doubledown,up;down=floor(number);up=ceil(number);printf(originalnumber%10.2lfn,number);printf(numberroundeddown%10.2lfn,down);printf(numberroundedup%10.2lfn,up);return0;}
运行结果:
originalnumber123.54numberroundeddown123.00numberroundedup124.00