C 库函数 - floor()

C 语言教程 · 2019-02-23 10:43:23

描述

C 库函数 double floor(double x) 返回小于或等于 x 的最大的整数值。

声明

下面是 floor() 函数的声明。

double floor(double x)

参数

  • x -- 浮点值。

返回值

该函数返回不大于 x 的最大整数值。

实例

下面的实例演示了 floor() 函数的用法。

#include <stdio.h>
#include <math.h>

int main ()
{
   float val1, val2, val3, val4;

   val1 = 1.6;
   val2 = 1.2;
   val3 = 2.8;
   val4 = 2.3;

   printf("Value1 = %.1lf\n", floor(val1));
   printf("Value2 = %.1lf\n", floor(val2));
   printf("Value3 = %.1lf\n", floor(val3));
   printf("Value4 = %.1lf\n", floor(val4));
   
   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

Value1 = 1.0
Value2 = 1.0
Value3 = 2.0
Value4 = 2.0

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

The Art of Computer Programming, Volume 3

The Art of Computer Programming, Volume 3

Donald E. Knuth / Addison-Wesley Professional / 1998-05-04 / USD 74.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 3》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具