C/C++取整函数:
函数名 |
功能说明 |
举例说明 |
floor() |
向负无穷大舍入(向下取整) |
floor(-10.5) == -11 floor(10.5)==10 |
ceil() |
向正无穷大舍入(向上取整) |
ceil(-10.5) == -10 ceil(10.5)==11 |
RoundEx() |
向最接近的整数取整(四舍五入) |
RoundEx(2.3)==2 RoundEx(2.6)==3 |
MATLAB取整函数:
函数名 | 功能说明 | 举例说明 |
---|---|---|
round(x) | x向最接近的整数取整(四舍五入) | round(4.2)=4 round(4.5)=5 |
fix(x) | x向0方向取整 | fix(4.2)=4 fix(4.5)=4 |
floor(x) | x向下取整 | floor(4.2)=4 floor(4.5)=4 |
ceil(x) | x向上取整 | ceil(4.2)=5 ceil(4.5)=5 |
可以看出在C和C++里面常用到的取整函数,在MATLAB里边都有,特别注意C/C++里边的四舍五入取整函数RoundEx()在MATLAB里边的表示方法为round()。