Binary Rounding Fundamentals
Rounding in decimal is something we all understand intuitively. The binary equivalent follows similar logic but can trip people up, especially when fractions enter the picture. Take 0.11101 rounded to 2 places after the point — the result being 1 isn't immediately obvious. This piece walks through the core rules for rounding binary fractions and the reasoning behind them. The very same rules hold for binary integers.
The IEEE-754 standard defines five rounding modes. Most of them are simple to grasp. The first two round towards the nearest value (one ties to even, the other ties away from zero). The remaining three are directed roundings: toward zero, toward positive infinity, and toward negative infinity. Looking at them in decimal first makes everything clearer:

The directed modes are easy to follow. The real focus here is the round to the nearest; ties to even rule. It's the standard for binary floating-point and the suggested default for decimal. It's also the one that often needs a closer look.
The main guideline for rounding a binary fraction to the n-th place is to examine the digit right after that position. If that digit is 0, round down. If it's 1 and any subsequent digit is also 1, round up. But if all the following digits are 0, you've hit a tie, and the 'ties to even' rule kicks in: round towards the option with a 0 in the n-th position.
Here's how that works with numbers rounded to 2 places:
- 0.11001 — rounds down to 0.11 since the 3-rd digit is 0
- 0.11101 — rounds up to 1.00 because the 3-rd digit is 1 and there's a 1 further along (at the 5-th spot)
- 0.11100 — this is a tie; since the 3-rd digit is 1 and the rest are 0, the 'ties to even' rule says round up.
If the logic behind these rules isn't immediately obvious, you're not alone. It’s rare to find an explanation that visualizes *why* these steps work. A good visual breakdown is often the key to a solid understanding.
Selecting Rounding Options
When rounding, you pick between two choices: the nearest number *below* the original or the nearest number *above* it. Both options must have no more digits after the point than your target precision.
Consider rounding the decimal 0.42385 to 2 places. Which two numbers are the candidates? Placing it on a number line with other two-place decimals makes it clear:

The original sits between 0.42 and 0.43. Since 0.42385 is 0.42 + 0.00385, the lower bound is simply 0.42. You get it by chopping off everything after the second decimal place. The upper bound is then found by adding one ULP to that lower bound — increase the last digit by one. Another way to see it is adding 0.01, which is 1 times 10 to the power of -2, matching the precision of two places. For three places, you'd do the same, adding 1 times 10 to the power of -3.
The rule for finding these candidates can be stated generally:
To round a fraction to n places, first find the lower number by discarding the digits after the n-th place. Then find the upper number by adding one ULP to the lower number — that's 1 multiplied by the base of the number system raised to the power of n.
Let's try this with the binary number 0.11011, again aiming for 2 places. Following the same pattern, the lower number is 0.11, as 0.11011 equals 0.11 + 0.00011. To find the upper number, add 0.01 — since we're in base 2, that's 1 times 2 to the power of -2. The result is 0.11 + 0.01 = 1.00.
Calculating the Nearest Option
The round to the nearest rule means picking the option with the smallest gap from the original number. On a number line, you'd look at the distances to both candidates. The one with the shorter distance wins.

A simple subtraction does the trick:

Here, x1 is clearly less than x2, so we round down to 0.11. But what if the number were infinitely long in binary? Subtraction becomes impractical. A smarter strategy is available.
Comparing Against the Midpoint
A different tactic is to check whether the original number lies above or below the midpoint between the two candidates. Logically, if it's above the midpoint, the upper option is closer; if below, the lower option is closer.

To locate that midpoint, we first note the span from 0.11 to 1.00 is 0.01. Half of that is 0.001. Adding it to the lower bound gives the center: 0.111. This turns out to be the same as simply adding a 1 to the end of the lower bound. Here's the visualization:

The final step is comparing the original number with the midpoint:

By checking the bits in lexicographical order, we see 0.11011 is smaller than the midpoint. So, round down to 0.11 — a result that matches our distance-based calculation.
Handling Tie Cases
Ties occur when the original number is exactly the midpoint, making the distance to both options equal. The 'round to the nearest' rule is then ambiguous. Imagine rounding 0.11011 to 4 places. The lower bound is found by truncation: 0.1101. The midpoint is formed by appending a 1: 0.11011. The upper bound uses the ULP addition: 0.1101 + 0.0001 = 0.1110.
So, the key values are:
– original number: 0.11011
– rounded down: 0.1101
– rounded up: 0.1110
– midpoint: 0.11011.
A direct bit comparison shows the original equals the midpoint, confirming a tie. This is where the 'ties to even' rule steps in. A binary integer is even if it ends in 0. Looking at our options, the upper one (0.1110) is even. The rule tells us to round up, choosing 0.1110.
Formulating the General Rules
Do you really need to compare every digit? No. The midpoint of two rounding options will always have a 1 at the n+1 position. Since the original and the midpoint share the same bits up to that point, the comparison can start there.
The full set of rules at the beginning of this article is essentially a shorthand for comparing the original against the midpoint. To review:
The general rule when rounding to the n-th place prescribes to check the digit following the n-th place in the number. If it's 0, then the number should always be rounded down. If, instead, the digit is 1 and any of the following digits is also 1, then the number should be rounded up. If, however, all of following digits are 0's, then a tie breaking rule must be applied and usually it's the 'ties to even'. This rule says that we should round to the number that has 0 at the n-th place.
