Rounding Negative NumbersDate: 05/23/2007 at 17:32:59 From: Paul Subject: Rounding negative numbers I was wondering what -0.5 is rounded to the nearest integer? My first impression was -1, but when we round 0.5 we round up, which would suggest -0.5 should be rounded to 0. Can you even round negatives? I asked a few mathematics graduates and did not get a convincing response, with both 0 and -1 being given. I thought that possibly you round the magnitude of the number and then deal with the negative, giving -1. However, we round 2.5, 1.5, 0.5 upwards, so to follow the pattern we would have to round -0.5 to 0. Date: 05/24/2007 at 10:36:00 From: Doctor Vogler Subject: Re: Rounding negative numbers Hi Paul, Thanks for writing to Dr. Math. The answer to your question is that there are many different ways of rounding. Some include (1) floor: round down to the next integer x-1 < floor(x) <= x (2) ceiling: round up to the next integer x <= ceiling(x) < x+1 (3) truncate: round toward zero trunc(x) = floor(x) when x >= 0 trunc(x) = ceiling(x) when x <= 0 (4) antitruncate: round away from zero (this is more rare) trunc(x) = ceiling(x) when x >= 0 trunc(x) = floor(x) when x <= 0 Then there are also the more familiar methods of rounding to the "nearest integer." But the trouble is that when you have half of an odd number, then there are two integers that are equally "near," so the above definition is ambiguous. I think that the most common method for resolving this confusion is to round halves up to the next integer: (5) round(x) = floor(x + 1/2) But you could also argue that this rule was placed so that you only have to look one decimal digit past the decimal point, and so you want 1.5 to round to the same number as 1.59. By this logic, you would also want -1.5 to round just like -1.59, in which case you might switch conventions when you have a negative number: (6) round(x) = floor(x + 1/2) when x >= 0 round(x) = ceiling(x - 1/2) when x <= 0 Of course, there is no reason why you can't do the opposite of either of those methods: (7) round(x) = ceiling(x - 1/2) (8) round(x) = ceiling(x - 1/2) when x <= 0 round(x) = floor(x + 1/2) when x >= 0 And in more special cases, you might prefer to do something else, like round down if the fraction is less than 1/3 and round up if the fraction is at least 1/3, as in (9) round(x) = floor(x + 2/3) The bottom line is that "round" is not as well-defined a term (mathematically) as the floor (sometimes called "greatest integer") and ceiling functions are, and you can choose to use whichever definition works best for you. But my personal opinion, when no more precise definition is given, would be to use definition (5), despite my argument for definition (6). If you have any questions about this or need more help, please write back, and I will try to offer further suggestions. - Doctor Vogler, The Math Forum http://mathforum.org/dr.math/ Date: 05/24/2007 at 15:06:55 From: Paul Subject: Thank you (Rounding negative numbers) Thanks for the help. |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/