Rounding to nearest

5.5k Views Asked by At

I have the number 0.101 in binary. I want to round it to 2 places after the radix point using the algorithm rounding to the nearest. Here is how I do it.

If I want to have two places, then I will have one of the two possible resulting numbers: 0.10 or 0.11. Let's see how by how much each is different from the original:

1) 0.101 - 0.10 = 0.11

2) 0.101 - 0.11 = 0.10

The second one gives us less difference then the first, so using the algorithm rounding to the nearest, 0.101 should be rounded to 0.11. Is this how the algorithm works?

1

There are 1 best solutions below

5
On BEST ANSWER

First of all your differences are wrong: 0.101 - 0.10 = 0.001 etc. Second rounding to nearest must be completed with a tie breaking rule if there are two representable numbers with the same difference to the number to be rounded; in your case both candidate numbers are $\pm 1/8$ from the original number:

0.101 - 0.10 =  0.001 = 1/8
0.101 - 0.11 = -0.001 = -1/8

Normally we would use round to nearest even (i.e. take the number with the least significant bit $0$) and in your case the result would be 0.10 because 0.11 is odd (the last bit is $1$).