函数
<cmath> <ctgmath>

floor

double floor (double x);
     double floor  (double x);      float floorf (float x);long double floorl (long double x);
     double floor (double x);      float floor (float x);long double floor (long double x);
     double floor (double x);      float floor (float x);long double floor (long double x);     double floor (T x);           // additional overloads for integral types
向下取整
x 向下取整,返回不大于 x 的最大整数值。

头文件 <tgmath.h> 提供了此函数的类型通用宏版本。
此头文件 (<cmath>) 为整数类型提供了额外的重载:这些重载在计算前有效地将 x 转换为 double(为T是任何整数类型而定义)。

参数

x
要向下取整的值。

返回值

x 向下取整后的值(以浮点值形式)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
/* floor example */
#include <stdio.h>      /* printf */
#include <math.h>       /* floor */

int main ()
{
  printf ( "floor of 2.3 is %.1lf\n", floor (2.3) );
  printf ( "floor of 3.8 is %.1lf\n", floor (3.8) );
  printf ( "floor of -2.3 is %.1lf\n", floor (-2.3) );
  printf ( "floor of -3.8 is %.1lf\n", floor (-3.8) );
  return 0;
}

输出

floor of 2.3 is 2.0
floor of 3.8 is 3.0
floor of -2.3 is -3.0
floor of -3.8 is -4.0


另见