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

查看所有标签

Algorithms to Live By

Algorithms to Live By

Brian Christian、Tom Griffiths / Henry Holt and Co. / 2016-4-19 / USD 30.00

A fascinating exploration of how insights from computer algorithms can be applied to our everyday lives, helping to solve common decision-making problems and illuminate the workings of the human mind ......一起来看看 《Algorithms to Live By》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具