Rules for rounding (positive and negative numbers)
I'm looking for clear mathematical rules on rounding a number to $n$ decimal places.
Everything seems perfectly clear for positive numbers. Here is for example what I found on math.about.com :
Rule One Determine what your rounding digit is and look to the right side of it. If that digit is $4, 3, 2, 1,$ or $0$, simply drop all digits to the right of it.
Rule Two Determine what your rounding digit is and look to the right side of it. If that digit is $5, 6, 7, 8,$ or $9$ add $1$ to the rounding digit and drop all digits to the right of it.
But what about negative numbers ? Do I apply the same rules as above ?
For instance, what is the correct result when rounding $-1.24$ to $1$ decimal place ? $-1.3$ or $-1.2$ ?
"Round to nearest integer" is completely unambiguous, except when the fractional part of the number to be rounded happens to be exactly $\frac 1 2$. In that case, some kind of tie-breaking rule must be used. Wikipedia (currently) lists six deterministic tie-breaking rules in more or less common use:
- Round $\frac 1 2$ up
- Round $\frac 1 2$ down
- Round $\frac 1 2$ away from zero
- Round $\frac 1 2$ towards zero
- Round $\frac 1 2$ to nearest even number
- Round $\frac 1 2$ to nearest odd number
Of these, I'm personally rather fond of "round $\frac 1 2$ to nearest even number", also known as "bankers' rounding". It's also the default rounding rule for IEEE 754 floating-point arithmetic as used by most modern computers. According to that rule,
$$\begin{aligned} 0.5 &\approx 0 & 1.5 &\approx 2 & 2.5 &\approx 2 & 3.5 &\approx 4 \\ -0.5 &\approx 0 & -1.5 &\approx -2 & -2.5 &\approx -2 & -3.5 &\approx -4. \\ \end{aligned}$$
Out of the six methods described in Ilmari's answer, one has two noticeable advantages: the "round away from zero" rule.
- We only need to look at a single place to determine which direction to round to.
When faced with e.g. 0.15X where X could be any digit, we don't need to concern ourselves with what X might be when rounding to 1 decimal place. If X is zero then the rule tells us to round to 0.2 and if it is non-zero then we would round to 0.2 anyway.
This also applies with the "round up" rule, but only for positive numbers. Any of the other rules could require us to examine X to determine whether or not we should round to 0.1 or 0.2.
This advantage holds true for negative numbers with the "round away from zero" rule. -0.15X will always round to -0.2 regardless of X. This works with the "round down" and "round towards zero" rule for negative numbers, but not any other rule.
"Round away from zero" is the only rule that has this benefit for both positive and negative numbers.
- Lack of bias
With the "round away from zero" rule, half of all numbers will be rounded up and half rounded down when the digit 5 is encountered. This means that for a random selection of numbers that you round to the same place, the exepcted average amount that you will round by is 0. This is because every digit that you round down is paired with a digit that you will round up (amount rounded in brackets):
1 9 (-1 +1)
2 8 (-2 +2)
3 7 (-3 +3)
4 6 (-4 +4)
5 5 (-5 +5) <-- for negative and positive numbers respectively
This advantage exists with some of the other rules, but with the others you lose the first advantage. With "round up" or "round down" you introduce a bias because the digit 5 will always result in a +5 or a -5 respectively.
Note that this only works if you expect to encounter positive and negative numbers with equal probability.