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

后端 未结 4 923
生来不讨喜
生来不讨喜 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.

    0 讨论(0)
  • 2021-01-22 17:27
    >> round([-0.5 0.5])
    
    ans =
    
        -1     1
    
    0 讨论(0)
  • 2021-01-22 17:31

    please type 'round(0.5)' in matlab... more efficient than writing on here

    0 讨论(0)
  • 2021-01-22 17:42

    This Rounding Functions Collection that is available on MATLAB Exchange might be of interest as well. It includes M-files/code for several rounding methods that are not included with MATLAB, and a pdf illustrating these together with the standard MATLAB rounding methods.

    0 讨论(0)
提交回复
热议问题