Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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, or 1, 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 one 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 ?

share|improve this question
    
-124? Do you mean -1.24? –  KennyTM Aug 27 '10 at 6:38
    
oops ! you're right, I corrected my question ! thx ! –  Jérôme Aug 27 '10 at 6:42
2  
This doesn't directly answer your question, but you might be interested in some of the rounding techniques posited at wikipedia: en.wikipedia.org/wiki/Rounding#Rounding_to_integer Of course, you'd have to scale your results appropriately to deal with non-integer rounding. –  Yonatan N Aug 27 '10 at 7:42
1  
Yonatan: Most of the disagreement anyway is how to handle the case when the digit after the rounding digit is a 5; for the other digits, all seem to be in agreement. I guess the rules are application-dependent! –  J. M. Aug 27 '10 at 10:32
    
You can round however you like. If there is a technical circumstance where a specific rounding method is needed it should be clear that this is the case. –  anon Aug 27 '10 at 17:05
add comment

1 Answer

up vote 8 down vote accepted

As others have noted, "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}$$

share|improve this answer
    
+1 for the nice explanation I was not aware of. –  Américo Tavares Aug 30 '11 at 13:54
    
I asked OP to unaccept my answer. –  Américo Tavares Aug 30 '11 at 14:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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