Round 函数
![](http://pubimage.360doc.com/wz/default.gif)
返回按指定位数进行四舍五入的数值。
ROUND(number, num_digits)
参数
number 必需。要四舍五入的数字。
num_digits 必需。位数,按此位数对 number 参数进行四舍五入。
更详细的解释说明
利用INT函数构造四舍五入的函数返回的结果精度有限,有时候满足不了我们的实际需要。Excel的Round函数可以解决这个问题。
ROUND函数中:
如果 num_digits 大于 0(零),则将数字四舍五入到指定的小数位。
如果 num_digits 等于 0,则将数字四舍五入到最接近的整数。
如果 num_digits 小于 0,则在小数点左侧进行四舍五入。
若要始终进行向上舍入(远离 0),请使用 ROUNDUP 函数。
若要始终进行向下舍入(朝向 0),请使用 ROUNDDOWN 函数。
若要将某个数字四舍五入为指定的倍数(例如,四舍五入为最接近的 0.5 倍),请使用 MROUND 函数。
实例
ROUND(2.15, 1) | 将 2.15 四舍五入到一个小数位 | 2.2 |
=ROUND(2.149, 1) | 将 2.149 四舍五入到一个小数位 | 2.1 |
=ROUND(-1.475, 2) | 将 -1.475 四舍五入到两个小数位 | -1.48 |
=ROUND(21.5, -1) | 将 21.5 四舍五入到小数点左侧一位 | 20 |
Function: round roundf roundl
Synopsis
#include <math.h>long double roundl(long double x);double round(double x);float roundf(float x);Description
The round functions will return a rounded integer in the specified format that will be rounded to the nearest integer regardless of the current rounding mode.
Returns
The rounded value.
例子:
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
函数功能:
四舍五入取整
使用方法:
B = round(A)
对数组A中每个元素朝最近的方向取整数部分,并返回与A同维的整数数组B,对于一个复数参量A,则分别对其实部和虚数朝最近的方向取整数部分,并返回一复数数据B。
应用举例:
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