MATLAB round function - how does it round .5 up or down?

后端 未结 4 931
生来不讨喜
生来不讨喜 2021-01-22 17:02

How does MATLAB\'s round function work with .5? Like 5.5? Does it round up to 6, or round down to 5? The Mathworks page talking about this function says nothing about this, and

4条回答
  •  一个人的身影
    2021-01-22 17:27

    Wikipedia knows:

    round(X): round to nearest integer, trailing 5 rounds to the nearest integer away from zero. For example, round(2.5) returns 3; round(-2.5) returns -3.

    There's a little more information on this scheme (Round half away from zero), and many others, in the article on rounding.

提交回复
热议问题