ceil round floor

ceil 是“天花板”  floor 是 “地板”  一个靠上取值,另一个靠下取值,如同天花板,地板。 

double floor(double x);

double ceil(double x);

使用floor函数。

floor(x)返回的是小于或等于x的最大整数。

如:     floor(10.5) == 10    floor(-10.5) == -11

使用ceil函数。

ceil(x)返回的是大于x的最小整数。

如:     ceil(10.5) == 11    ceil(-10.5) ==-10

floor()是向下取整,floor(-10.5) == -11;

ceil()是向上取整,ceil(-10.5) == -10

ceil(x)返回不小于x的最小整数值(然后转换为double型)。

floor(x)返回不大于x的最大整数值。

round(x)返回x的四舍五入整数值。

#include <stdio.h>

#include <math.h>

int main(int argc, const char *argv[])

{

float num = 1.4999;

printf("ceil(%f) is %f\n", num, ceil(num));

printf("floor(%f) is %f\n", num, floor(num));

printf("round(%f) is %f\n", num, round(num));

return 0;

}

ceil(1.499900) is 2.000000

floor(1.499900) is 1.000000

round(1.499900) is 1.000000

ceil round floor

时间: 2024-08-07 16:44:58

ceil round floor的相关文章

oracle中的turnc,round,floor,ceil函数

这四个函数有点类似java中的函数,首先是 trunc(number,[decimals]) 这个函数类似截取函数 number:表示你要输入的数 decimals(小数): 表示你要截取的位数[正数表示小数点向右保留多少位,负数向左依次置零且小数点右边的截断] eg: select trunc(35.34,1) from dual; result: 35.3 select trunc(35.34,3) from dual; result:35.34 select trunc(35.34,-1)

MATLAB中取整函数(fix, floor, ceil, round)的使用

MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3    -3(2)floor(x):不超过x 的最大整数.(高斯取整) >> floor( [3.12 -3.12]) ans = 3    -4 (3)ceil(x) : 大于x 的最小整数 >> ceil( [3.12 -3.12]) ans = 4    -3 (4)四舍五入取整 >> round(3.12 -3.12) ans = 0 &

delphi的取整函数round、trunc、ceil和floor

首先引入math单元 uses math; 1.Round(四舍六入五留双) 功能说明:对一个实数进行四舍五入.(按照银行家算法) 例: var i, j: Integer; begin i := Round(1.5); // i等于2 j := Round(2.5); // j等于2 end; 在Delphi中使用Round函数得到的答案有时与我们所预期的会不太一样:采用的是四舍六入五留双.即当舍或入位大于或小于五时按四舍五入来处理 ,而当舍或入位等于五时,就要看前面一位是什么,根据奇进偶不进

php取整函数ceil,floor,round,intval函数的区别

开发过程中,遇到数据处理取整的时候,你会用哪个呢,小涛来介绍一下:PHP取整函数有ceil,floor,round,intval,下面详细介绍一下: 1.ceil — 进一法取整说明float ceil ( float $value )返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大.ceil() 例子 <?php echo ceil(4.3); // 5 echo cei

paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用

MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans =      3    -3 (2)floor(x):不超过x 的最大整数.(高斯取整) >> floor( [3.12 -3.12]) ans =      3    -4 (3)ceil(x) : 大于x 的最小整数 >> ceil( [3.12 -3.12]) ans =      4    -3 (4)四舍五入取整 >> round(3.12

[转]PHP取整函数:ceil,floor,round,intval的区别详细解析

我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大. PHP取整函数例子 1. ceil() 例子 echo ceil(4.3); // 5 echo ceil(9.999); // 10 2.flo

Math类中round、ceil和floor方法的功能

Java中的Math工具类用来完成除+.-.*./.%等基本运算以外的复杂运算,位于java.lang包下,Math类的构造器全是私有的(private),因此无法创建Math类的对象,Math类的方法全是类方法,可以直接通过类名来调用它们.下面重点介绍Math类中经常用到的几个方法,也是面试时经常被问到的知识点. 1.round round方法表示四舍五入.round意为“环绕”,其原理是在原数字的基础上先加上0.5再向下取整,它的返回值为int类型,例如,Math.round(11.5)等于

C++中的 Round(),floor(),ceil()

 2.1             2.6               -2.1               -2.6floor : 不大于自变量的最大整数             2                2                  -3                  -3ceil   :不小于自变量的最大整数              3                3                  -2                  -2round:四舍五入到

MATLAB取整函数 fix floor ceil round

MATLAB取整函数 (1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3    -3 (2)floor(x):不超过x 的最大整数.(高斯取整) >> floor( [3.12 -3.12]) ans = 3    -4 (3)ceil(x) : 大于x 的最小整数 >> ceil( [3.12 -3.12]) ans = 4    -3 (4)四舍五入取整 >> round(3.12 -3.12) ans = 0