玉石雕刻培训:关于round函数
来源:百度文库 编辑:神马品牌网 时间:2024/10/06 08:50:30
x = -13.2
y = 0.32
z = nit ( x )
e = abs ( z + round(y * 5 ) )
print z
print e
end
我想问下那个"round"这个函数是表示的是什么意思?
能详细的给我说说下吗?
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()
round函数可能是自定义的四舍五入函数,以实现四舍五入的功能。例如:ROUND(4.5)=5,ROUND(4.4)=4。在QBASIC中,可以用INT函数来直接实现四舍五入,INT函数的格式是INT(X),它可以实现取整的功能,例如INT(4.4)=4,INT(4.8)=4。在将它稍稍变化后,可实现四舍五入,格式为:INT(X+0.5),例如:将4.4四舍五入,INT(4.4+0.5)=4,将4.8四舍五入,INT(4.8+0.5)=5。