I’ve learned something today. Apparently, there’s more than one way to round a number. There’s the easy, “common” method that everyone learns, where you simply look at the digits you want to zero-out, and if the first digit is >= 5 you round up, and <= 4 you round down.
And then there’s the number-nerd way called “round-to-even”. From Wikipedia’s article on Rounding:
- Decide which is the last digit to keep.
- Increase it by 1 if the next digit is 6 or more, or a 5 followed by one or more non-zero digits.
- Leave it the same if the next digit is 4 or less
- Otherwise, if all that follows the last digit is a 5 and possibly trailing zeroes; then change the last digit to the nearest even digit. That is, increase the rounded digit if it is currently odd; leave it if it is already even.
For example:
- 3.013 rounded to hundredths is 3.01 (because the next digit (3) is 4 or less)
- 3.015 rounded to hundredths is 3.02 (because the next digit is 5, and the hundredths digit (1) is odd)
- 3.045 rounded to hundredths is 3.04 (because the next digit is 5, and the hundredths digit (4) is even)
This came up for me while trying to figure out how MySQL rounds numbers. Rather than create a new ROUND() function, they modified its behavior between versions. This is documented, at least, and provides a more predictable result independent of the OS. However, I am not clear on the unspecified distinction between an “exact value” and an “approximate value”. More number-nerd stuff, I assume.

