MATLAB 取整函数
floor
floor 函数将浮点数向下取整为最接近的整数,结果总是小于或等于输入值。
语法:
output = floor(input)登录后复制
示例:
>> floor(3.14) 3 >> floor(-1.5) -2登录后复制
ceil
ceil 函数将浮点数向上取整为最接近的整数,结果总是大于或等于输入值。
语法:
output = ceil(input)登录后复制
示例:
>> ceil(3.14) 4 >> ceil(-1.5) -1登录后复制
round
round 函数将浮点数取整为最接近的整数,结果可能小于、等于或大于输入值。默认情况下,0.5 向上取整,-0.5 向下取整。
语法:
output = round(input)登录后复制
示例:
>> round(3.14) 3 >> round(-1.5) -2 >> round(3.5) 4登录后复制
其他选项
- round(x, n):将 x 取整到小数点后 n 位。floor(x, n):将 x 向下取整到小数点后 n 位。ceil(x, n):将 x 向上取整到小数点后 n 位。
以上就是matlab取整函数怎么取的详细内容,更多请关注楠楠科技社其它相关文章!