tags:

views:

238

answers:

4

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 the example doesn't help either!

Here is the mathworks page for the MATLAB round function:

mathworks round function page

+4  A: 

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.

Michael Petrotta
Let the wars begin between that banker's rounding people and the away from zero people...banker's rounding = always round to an even number digit (0,2,4,6,8) to facilitate any division lateraway from zero = always round up in an absolute sense and apply the sign later.
jalexiou
+2  A: 
>> round([-0.5 0.5])

ans =

    -1     1
MatlabDoug
A: 

0.5 is the threshold at which starts rounding up, but you shouldn't really be concerned with this, because most computations are not bound to give exactly 0.5. A deviation from even a single bit might cause it to round down instead.

André Caron
+1  A: 

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

anom

related questions