永发信息网

roundn函数怎么使用

答案:1  悬赏:0  手机版
解决时间 2021-02-26 14:15
  • 提问者网友:箛茗
  • 2021-02-25 20:34
roundn函数怎么使用
最佳答案
  • 五星知识达人网友:雪起风沙痕
  • 2021-02-25 21:49
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()
应用举例:
a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
a =
Columns 1 through 4
-1.9000 -0.2000 3.4000 5.6000
Columns 5 through 6
7.0000 2.4000 + 3.6000i
round(a)
ans =
Columns 1 through 4
-2.0000 0 3.0000 6.0000
Columns 5 through 6
7.0000 2.0000 + 4.0000i
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯