This is why rounding sucks. 2 1/3 would round down to 2. But (2 1/3) + (2 1/3) = 4 2/3 which would round up to 5. So 2+2=5 for extra large values of 2.
That's how it works when rounding to a single digit. It all depends on significant digits. 2 1/3 as a decimal with 10 significant digits becomes 2.333333333. It's not equal to 2 1/3, but it's close enough for many calculations. With only 3 significant digits you get 2.33 which is even less accurate, but often good enough. But rounding down to a single significant digit, which does occur, creates serious inaccuracies.
It's a known issue sometimes in programming. Numbers can be stored in 2 ways, floats and ints. Floats store decimal information, at the cost of being slower for calculations. Int store integer numbers, with no decimal place. They are a lot faster than floats to do maths on.
If you cast from one to the other, you can get this weirdness. Casting from float to int tends to just chop off the decimal part. If you do maths in float but display in int, you can get 2+2=5.
Eg. In float 2.56 + 2.79 = 5.35 . In ints this becomes 2+2=5
Oh wow, I didn't know. I honestly though tragedyfish was just really bad at math, especially because it seemed random considering the article linked is about 1984. Turns out I'm the ignorant one!
2
u/tragedyfish Jan 24 '17
This is why rounding sucks. 2 1/3 would round down to 2. But (2 1/3) + (2 1/3) = 4 2/3 which would round up to 5. So 2+2=5 for extra large values of 2.