slogan 专业知识问答平台!
佰学网 >生活问答 > 知识 > round()函数的用法

round()函数的用法

原创 2022-03-03 15:56:41
round()函数round函数功能:四舍五入取整。使用方法:B=round(A.. 精选答案
  • 问题相关

round()函数

round函数功能:四舍五入取整。

使用方法:

B = round(A)

对数组A中每个元素朝最近的方向取整数部分,并返回与A同维的整数数组B,对于一个复数参量A,则分别对其实部和虚数朝最近的方向取整数部分,并返回一复数数据B。

举例:

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;

}

编译:$cc test.c -lm

执行:$./a.out

ceil(1.499900) is 2.000000

floor(1.499900) is 1.000000

round(1.499900) is 1.000000

Matlab中round()

©本文版权归作者所有,任何形式转载请联系我们:xiehuiyue@offercoming.com。

相关内容推荐

来自百学网

刘老师

刘老师

中国人大教育学硕士

关注

你可能关心