matlab 小数点取前两位 您所在的位置:网站首页 matlab保留小数点 matlab 小数点取前两位

matlab 小数点取前两位

2023-08-11 01:59| 来源: 网络整理| 查看: 265

Matlab取整函数有: fix, floor, ceil, round.取整函数在编程时有很大用处。

一、取整函数

1.向零取整(截尾取整)

fix-向零取整(Round towards zero);

>> fix(3.6)

ans =      3

2.向负无穷取整(不超过x 的最大整数-高斯取整)

floor-向负无穷取整(Round towards minus infinity);

>> floor(-3.6)

ans =     -4

3.向正无穷取整(大于x 的最小整数)

ceil-向正无穷取整(Round towards plus infinity);

>> ceil(-3.6)

ans =     -3

4.向最近整数取整,四舍五入(四舍五入取整)

round-向最近整数取整,四舍五入(Round towards nearest integer);

>> round(3.5)

ans =      4

二、在小数点后某一位四舍五入,即保留几位小数,也经常用到。

1.数值型 roundn—任意位位置四舍五入

>>a=123.4567890;

>>a=roundn(a,-4)

a =   123.4568

其中roundn函数功能如下:

y = ROUNDN(x) rounds the input data x to the nearest hundredth.   %不指定n,精确到百分位 y = ROUND



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有