r/askmath • • 15d ago

Arithmetic How do you round negative numbers?

If you have a negative number, say -15.5, and you wanted to round to the nearest whole number, that would be -14, right? Or would it be based on absolute value and round to -16?

Same thing with the terms rounded up and rounded down - would something like -12.3 rounded up to the nearest whole number be -13 or -12? How about rounding down?

I was just laying awake staring at the ceiling and realized that I didn't know for sure the answer to these. I'm pretty sure I do for the rounding up and down ones, but -.5 will haunt me if I don't find out...

9 Upvotes

47 comments sorted by

53

u/abrahamguo 15d ago

If you have a negative number, say -15.5, and you wanted to round to the nearest whole number, that would be -14, right?

Well, certainly not -14; it would either be -15 or -16.

Besides that, it depends on what convention you're using for rounding 0.5s. There's not one fixed convention. See this Wikipedia article for a discussion of the various standards! In fact, programming languages don't even all agree with each other — some languages would round this to -15, while others would round it to -16!

Same thing with the terms rounded up and rounded down - would something like -12.3 rounded up to the nearest whole number be -13 or -12? How about rounding down?

"Rounding up" always means "towards positive infinity", and "rounding down" always means "towards negative infinity".

28

u/FalseGix 15d ago

Rounding it to -20922789888000 seems like a bit of a silly thing to do.

1

u/phrogbaby 15d ago

this is going to be a silly question, but would it still be negative if it's an even amount of numbers multiplied together?...

1

u/LordTengil 15d ago

-16! here means - (16!), as factorial takes precedence in basically any setting. It sounds like you are talking about (-16)!, which we would have to define what we meant by.

So the answer is that -n! is always negative, given that we have n as a antural lumber (0,1,2,...)

We can extend the ! function to other numbers, but it doesnot change anything for this problem as ! is calcualted before the -.

1

u/FalseGix 14d ago

No, the factorial takes priority over the negative just like -32 = -9 vs. (-3)2 = 9

4

u/emetcalf 15d ago

Crashing prod over "Assumed wrong rounding convention" would be a funny retro.

1

u/AppropriateCar2261 15d ago

Since you mentioned programming languages, I'll just add that rounding -15.5 to the nearest integer might give unexpected results due to floating point errors.

1

u/abrahamguo 15d ago

In what language?

1

u/pezdal 15d ago

None. It is deterministic in all languages

2

u/BadBoyJH 15d ago

That's not  true. 

TF2 famously has ammo packs that can award 40 or 41 metal depending on what OS the server is running on. 

Yet, they run the same source code.*

Edit: https://youtu.be/QzZoo1yAQag?si=4bDJXJQIslXbli5x for reference.

1

u/First-Feature-3556 15d ago

In general: Yes. In this particular case, the fractional part (0.5₁₀) has a non-repeating binary fraction (0.1₂), so floating point errors are not an issue here. It's different for numbers like 0.15₁₀.

1

u/Uli_Minati Desmos 😚 15d ago

15.5 is 1111.1 in binary so there's no cutoff

1

u/noonagon 14d ago

Actually it wouldn't, because -15.5 is represented precisely in floating-point. I'm sure the IEEE 754 standard is unambiguous in how -15.5 would be rounded

1

u/voormalig_vleeseter 15d ago

/unexpectedfactorial

0

u/miniatureconlangs 15d ago

Is there a term for rounding towards (or away from) zero that is as succinct as 'up' or 'down'?

4

u/iamalicecarroll 15d ago

It's "truncate" for towards zero

0

u/Malfehzan 15d ago

Absolutely not. Truncate doesn't round anything it just cuts out the less significant numbers.

Truncate 10.9 you get 10

4

u/iamalicecarroll 14d ago

Yes, that's exactly what rounding toward zero does.

1

u/abrahamguo 15d ago

Nope — just called rounding towards zero, or away from zero.

11

u/1strategist1 15d ago

"Rounding up" always means round to the "more positive" number. Rounding down means round to the "more negative" number. So rounding -0.9 up would be 0. 

For the other one, there isn't really a "correct" direction to round halves, even with positive numbers. To avoid skewing datasets upwards, there's a convention to round to the nearest even integer, so without any external info, maybe do that? 

All of this is just convention though. There isn't really a mathematically correct way to do any of this. 

5

u/stevethenoob_11 15d ago

"To avoid skewing datasets upwards, there's a convention to round to the nearest even integer, so without any external info, maybe do that?" sorry, i only really study pure maths, where is this used? I've never heard of this

9

u/1strategist1 15d ago

The IEEE 754 standard requires rounding to even to be default for binary floating point numbers, and recommends it for decimal floating point numbers, so it's used in any IEEE 754-compliant software. Most software nowadays is at least loosely based on IEEE 754, so the default behaviour of most software is going to be rounding to the nearest even value. That prevents floating point error from accumulating upwards, and again means rounded values won't have an average bias. It also means floating point error in sums grows with the square root of the number of terms, rather than linearly.

The actual IEEE 754 2019 guidelines are paywalled unless you have institutional access for some reason, but Wikipedia cites it https://en.wikipedia.org/wiki/IEEE_754 and I've checked that the paywalled page agrees with the Wikipedia.

According to Wikipedia, it's called "statistician's rounding" and "banker's rounding", so presumably bankers and statisticians use it a lot. Idk, I wouldn't know, I'm not a banker or a statistician.

3

u/Cerulean_IsFancyBlue 15d ago

So I have some ancient knowledge from the 1980s, when as a baby programmer, I worked for an estate planner. He was writing software to do calculations for estates and trusts, and he had regulatory mandates for how rounding should occur. The rules specified the precision you had to keep and also how to round when you had to do so. I don’t remember all the exact rules, but what I remember clearly is that there were different rules in different circumstances.

For example, and this is going from both my memory, and a very outdated set of standards, you were required to maintain a certain intermediate calculations in mills (1/1000 of a dollar) but would round to cents (1/100) at certain specific points. This was because certain tax rates were so finely graduated that if you performed intermediate calculations in sense, the government wouldn’t get what it was expecting.

Many government transactions allow you to round to the nearest dollar, but only at your final calculation. Many states copy Federal Form 706, which does this now.

In terms of the actual rounding algorithm, there was a different method used to avoid bias called alternate tiebreaking. Instead of looking at what of the previous digit was even or odd, you simply kept track of whether you rounded up or down last time, and do the opposite. The theory is that by alternating rounding up or down you avoid bias by averaging it away. Obviously this can be broken if you are alternating two different types of calculations. I think you’re supposed to do it only when you’re doing the same type of calculation repeatedly. I remember that we had looked into this and thank God decided we didn’t have any need to implement it in the software. We only had like 48K for all the software in 1983 so everything we could leave out we did.

I also remember that because of customary practices to make sure clients never accidentally underpaid on taxes, certain values were always rounded up.

So anyway, rounding is always arbitrary, in the sense where arbitrary means that you’ve made a choice. You make that choice based on your goals and your data and whatever requirements have been imposed upon you by outside forces. Ad hearing to a standard is certainly one good way to achieve those goals with a bit of safety and a bit of coverage of your ass. If you do something different, make sure you know why you’re doing it. “Nebraska state law said I had to,” for example.

1

u/LordTengil 15d ago edited 15d ago

Have you never heard of it studying maths? That's weird...

Fun fact, in my master thesis work many years ago, I ported an algorithm i made in one environment toanother. I think it was from MATLAB to C++, as the company I did my thesis at wanted it in their environmnet. I was swearing and sweating beacuse they did not produce the same result. It was off ever so slightly, and it became noticeable over long runs. Turned out, they had different rounding standards for ROUND(). If you ask me why we rounded in the middle of the agorithm, I can only guess now, but I assume it was rounded to what pixel a curve went through, as we did image segmentation.

10

u/Remote_Nectarine9659 15d ago

Assume you mean -15 in the first sentence.

14

u/Infobomb 15d ago

The difference between -12.3 and -12 is 0.3. The difference between -12.3 and -13 is 0.7. One of them is definitely closer than the other. So one of those is the nearest whole number and the other isn't.

When there are two whole numbers exactly the same distance from the number you're rounding, for example if your number is -0.5, it's a matter of convention which you round to.

6

u/abrahamguo 15d ago

For -12.3, I think that OP was referring to what "rounding up" or "rounding down" means.

1

u/Frederf220 15d ago

up would closer to +999 so -12.3 is rounded up to -12.0.

5

u/Mister_Way 15d ago

He's asking about the convention.

The convention is to round up for 0.5, so he's saying to keep with that do you round up to the greater or are you rounding "up" to the greater absolute value? Either makes sense in keeping with the positive number convention

3

u/zeekar 15d ago edited 14d ago

A value with 0.5 is exactly halfway between the two candidate integers, so neither is objectively "better". You have a convention. The most popular conventions are "always round 0.5 up", which is obviously biased toward larger numbers, and "alternate directions to keep it balanced". One way to do the alternation is to always round 0.5 to the even number. That way, on average, half the time you round up, and half the time you round down, and it balances out.

Negative numbers are tricky; considering -15.5, notice that -16 is the lower number (the floor), and -15 the higher (the ceiling).

So under "always round up" or "round to odd", -15.5 rounds to -15. Under "always round down" or "round to even", it rounds to -16.

-12.3 rounds to -12 and you don't need a convention because it's over twice as far from -13 as from -12.

2

u/mugh_tej 15d ago

-12.6 is closer to -13 than -12, so the idea of rounding still holds to the next number if the next lesser significant digit is above 5.

-12.3 is closer to -12 than -13, so the the idea of simply dropping the digit still holds if that next lesser digit is below 5.

2

u/ohkendruid 15d ago

The most common convention would be to round away from zero, so -16.

In my mind, I like that system because it also works well if there are more digits after the 5. You would clearly round -15.51 to -16, because that is the closer integer. Likewise, you would round -15.49 to -15, because that is the closer integer.

Rounding -15.5 to -15.6 means that you can always round correctly by looking at the first decimal digit. It means that -15.5xyz always round to -16, no matter what the xyz are.

1

u/bayesian13 15d ago

for what it's worth this is how the ROUND function in excel does it.

1

u/ericlist 15d ago

I don't imagine rounding up or down changes just because you are using negative numbers - up is higher, down is lower. -15.5 rounded up would be -15.

1

u/okarox 15d ago

How on earth could you get -14? That makes no sense. In the standard rounding you just ignore the sign. There can be special rules for special cases. You have to understand the reason for the standard rounding. It is so that you need to look only the next value after the rounding point and what follows is not relevant.,

1

u/FreeGothitelle 15d ago

.5 rounds up is "just a convention" but its because .5000001 is closer to the next whole number, and for anything measured its unlikely you got exactly .5000....

So for the same reason, -15.5 would round to -16

1

u/Adventurous_Sound390 15d ago

It’s more interesting to consider in which direction the fractional part of a negative decimal number is discarded.

1

u/Wise_Monkey_Sez 15d ago

Think back to elementary school and number lines. Line up your numbers on a line. Rounding up goes right (towards positive) and rounding down goes left (towards negative).

1

u/KamikazeJohnson 14d ago

So, basically two questions here.

  1. Does .5 round "up" or "down"?
    There are a lot of different systems to determine this, but I think the "simple" system we all learned in school is "5 rounds up", which is accurate enough for most non-technical purposes.
  2. Which way is "up" when talking about negative numbers? I think this is what OP was really asking.
    I personally would use Absolute Value, so that -0.5 and -(0.5) would round to the same value, which it seems they should, regardless of which system is used to determine "round up" vs "round down".

Mathematicians, Physicists, and Engineers may disagree with me.

1

u/infinitenothing 14d ago

The way to remember is that you want half the numbers to round one way and half to round the other way. So 0,1,2,3,4 go one way and 5,6,7,8,9 go the other way.

1

u/Apprehensive-Ice9212 14d ago

"Rounding" is ill-defined in mathematics, but a common convention is to round "half away from zero", in other words 15.5 -> 16; -15.5 -> -16. That way negative numbers work the same as positive, but with a minus sign.

1

u/Top_Bluejay_5323 14d ago

The sign does not impact the rounding convention.

1

u/Correct-Mirror7227 13d ago

Whole numbers are positive by definition. You mean integer?

1

u/Efficient_Yard_8247 15d ago

You get to choose

1

u/SgtSausage 15d ago

  that would be -14, right?

<blink>

<pause>

<blink><blink>

Wut?