According to the Mathematica help:

Round rounds numbers of the form x.5 toward the nearest even integer.

For example:

Round[{0.5, 1.5, 2.5, 3.5, 4.5}]

gives

{0, 2, 2, 4, 4}

What's the rationale behind this? Why not the usual x.5 always rounds up?

link|improve this question

feedback

2 Answers

up vote 12 down vote accepted

It is called bankers rounding. The rationale is that the rounding behaves "nicely" even if you have negative numbers, i.e. rounding commutes with negation, which is nice.

link|improve this answer
Besides that rounding to even ensures you still have an integer if you divide the rounded result by two later on. Chemist normally round to even when measurements and computations are rounded to the nearest 0.001 and stuff like that. – Ted Ersek Feb 22 at 0:19
2  
That's a nice property, but rounding away-from-zero does has the same property, and is more intuitive. I'm pretty sure the true reason is Mr. Wizard's answer. – BlueRaja - Danny Pflughoeft Feb 22 at 4:36
feedback

I think the reason is to prevent biasing numbers on average upward or downward.

For example if you have a list of numbers that include a lot of x.5 and you were to round all these upward, the average magnitude of the list would also shift upward. Likewise if you round downward, downward.

By rounding to the nearest even number these would balance out, given enough samples.


SetAttributes[RoundUp, Listable]
RoundUp[a_] := If[FractionalPart[a] >= 1/2, Ceiling[a], Floor[a]]

d = Table[i, {i, 0, 100, 1/10}];

Mean[Round[d]] // N
50.
Mean[RoundUp[d]] // N
50.05
Mean[d]
50
link|improve this answer
1  
@Brett: nice example!! – Thomas Feb 22 at 9:15
Just as an aside, Floor[a + 1/2] is the traditional way to round positive numbers in C++ (which has no built in round function). – wxffles Feb 22 at 20:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.