TExcelTAD
Home › Basic Math & Pre-Algebra › Rounding and Repeating Decimals

Rounding and Repeating Decimals

Some decimals stop, others repeat a block of digits forever, and both often need rounding to a sensible number of places. This lesson rounds to a chosen place, explains the different tie-breaking rules (including the one Python's round() uses), and shows how to find the repeating block of any fraction and turn a repeating decimal back into a fraction.

Rounding to a decimal place

To round to a given place, look at the next digit to the right:

  • 0–4: round down (keep the digit, drop the rest).
  • 5–9: round up (add 1 to the digit, drop the rest).
Number To 1 place To 2 places To whole number
3.14159 3.1 3.14 3
2.678 2.7 2.68 3
0.0449 0.0 0.04 0
9.995 10.0 10.00 (tie, rounded up) 10

Look only at the one next digit. Rounding 0.0449 to two places looks at the third digit (4), so the answer is 0.04, even though 0.045 would round up. Rounding twice (0.0449→0.045→0.050.0449 \to 0.045 \to 0.05) gives a different, wrong answer.

Ties: half up or half to even?

When the dropped part is exactly 5 (2.5, or 0.125 to two places), there are two common rules:

  • Round half up (school rule): 2.5→32.5 \to 3, 3.5→43.5 \to 4, 0.125→0.130.125 \to 0.13.
  • Round half to even ("banker's rounding"): go to the neighbour whose last digit is even: 2.5→22.5 \to 2, 3.5→43.5 \to 4, 0.125→0.120.125 \to 0.12.

Half to even avoids a bias: with half up, ties always go up, so totals of many rounded numbers creep upward. Python's built-in round() uses half to even:

python · try it yourself
print([round(x) for x in [0.5, 1.5, 2.5, 3.5, -2.5]])
print(round(2.675, 2))     # expect 2.68? the float is really 2.67499999...
[0, 2, 2, 4, -2]
2.67

The second line is not banker's rounding at all: the float 2.675 is stored as 2.67499999999999982236431605997495353221893310546875, which is below the tie, so it rounds down. To round exactly as written, use Decimal and choose the rule explicitly:

python · try it yourself
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN, ROUND_CEILING

x = Decimal("2.675")
cent = Decimal("0.01")
for rule in [ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN, ROUND_CEILING]:
    print(f"{rule:16} {x.quantize(cent, rounding=rule)}")

print(Decimal(2.675))      # what the float really holds
ROUND_HALF_UP    2.68
ROUND_HALF_EVEN  2.68
ROUND_DOWN       2.67
ROUND_CEILING    2.68
2.67499999999999982236431605997495353221893310546875

Here half up and half even agree, because the 8 in 2.68 is already even. Try Decimal("2.665") and they differ (2.67 vs 2.66).

Repeating decimals

Dividing the numerator by the denominator either stops or falls into a loop. It must loop eventually: in long division by dd, the remainder is always one of 0,1,…,d−10, 1, \ldots, d - 1, so after at most dd steps a remainder repeats, and from then on the digits repeat too.

13=0.333…=0.(3)block of 1 digit311=0.2727…=0.(27)block of 2 digits16=0.1666…=0.1(6)one digit, then the repeat17=0.142857142857…=0.(142857)\begin{aligned} \frac{1}{3} &= 0.333\ldots = 0.(3) && \text{block of 1 digit} \\ \frac{3}{11} &= 0.2727\ldots = 0.(27) && \text{block of 2 digits} \\ \frac{1}{6} &= 0.1666\ldots = 0.1(6) && \text{one digit, then the repeat} \\ \frac{1}{7} &= 0.142857142857\ldots = 0.(142857) \end{aligned}

The bracket (or a bar over the digits, in books) marks the repeating block. A fraction in lowest terms terminates exactly when its denominator has no prime factors other than 2 and 5.

This program does the long division and stops when a remainder comes back:

python · try it yourself
def expand(num, den):
    whole, rem = divmod(num, den)
    digits, seen = [], {}
    while rem and rem not in seen:
        seen[rem] = len(digits)
        rem *= 10
        digits.append(str(rem // den))
        rem %= den
    if not rem:
        return f"{whole}." + "".join(digits) if digits else str(whole)
    start = seen[rem]
    return f"{whole}." + "".join(digits[:start]) + "(" + "".join(digits[start:]) + ")"

for n, d in [(1, 8), (1, 3), (3, 11), (1, 6), (1, 7), (5, 12), (22, 7)]:
    print(f"{n}/{d} = {expand(n, d)}")
1/8 = 0.125
1/3 = 0.(3)
3/11 = 0.(27)
1/6 = 0.1(6)
1/7 = 0.(142857)
5/12 = 0.41(6)
22/7 = 3.(142857)

From repeating decimal back to a fraction

Let x=0.272727…x = 0.272727\ldots The block has 2 digits, so multiply by 102=10010^2 = 100 and subtract:

100x=27.2727…x=0.2727…99x=27→x=2799=311\begin{aligned} 100x &= 27.2727\ldots \\ x &= 0.2727\ldots \\ 99x &= 27 && \to x = \frac{27}{99} = \frac{3}{11} \end{aligned}

The rule: a block of kk digits that starts right after the point equals that block over kk nines. 0.(142857)=142857999999=170.(142857) = \frac{142857}{999999} = \frac{1}{7}, and 0.(9)=99=10.(9) = \frac{9}{9} = 1, which is why 0.999…0.999\ldots equals exactly 1.

Note: When you round a repeating decimal (13≈0.33\frac{1}{3} \approx 0.33), you lose information; Fraction(1, 3) keeps it. Fraction("0.33") is 33100\frac{33}{100}, not 13\frac{1}{3}, and Fraction(0.33).limit_denominator(100) can recover a simple fraction that is close.

In software

  • Currency rounding rules are legal requirements, not style: some tax rules demand half up, many banking systems use half even, and some currencies round to 0.05. Always pass the rule explicitly (quantize(…, rounding=…)).
  • Display vs storage: format for display (f"{x:.2f}"), but keep the full value for further calculation, or the errors compound.
  • Ceiling division for pages or batches: 47 items at 10 per page need ⌈4.7⌉=5\lceil 4.7 \rceil = 5 pages. In integers: -(-47 // 10).

Exercises

Exercise 1: Round it

Round 18.0462 to one, two and three decimal places.

Answer

18.0, 18.05, 18.046

Solution
1 place:next digit 4→keep→18.02 places:next digit 6→up→18.053 places:next digit 2→keep→18.046\begin{aligned} \text{1 place:} &\quad \text{next digit } 4 \to \text{keep} && \to 18.0 \\ \text{2 places:} &\quad \text{next digit } 6 \to \text{up} && \to 18.05 \\ \text{3 places:} &\quad \text{next digit } 2 \to \text{keep} && \to 18.046 \end{aligned}

Exercise 2: Tie rules

Round 0.125 and 0.135 to two places with round half up and with round half to even.

Answer

Half up: 0.13 and 0.14. Half even: 0.12 and 0.14.

Solution

Both are exact ties. Half up always goes up. Half even picks the neighbour ending in an even digit: 0.12 (not 0.13) and 0.14 (not 0.13).

python · try it yourself
from decimal import Decimal as D, ROUND_HALF_UP, ROUND_HALF_EVEN
for x in ["0.125", "0.135"]:
    q = D("0.01")
    print(x, D(x).quantize(q, ROUND_HALF_UP), D(x).quantize(q, ROUND_HALF_EVEN))
0.125 0.13 0.12
0.135 0.14 0.14

Exercise 3: Repeating block

Write 49\frac{4}{9} and 712\frac{7}{12} as decimals, marking the repeating part.

Answer

49=0.(4)\frac{4}{9} = 0.(4) and 712=0.58(3)\frac{7}{12} = 0.58(3)

Solution

4÷94 \div 9: remainder 4 every step, digit 4 forever. 7÷127 \div 12: 70÷12=5 r 1070 \div 12 = 5 \text{ r } 10; 100÷12=8 r 4100 \div 12 = 8 \text{ r } 4; 40÷12=3 r 440 \div 12 = 3 \text{ r } 4; remainder 4 repeats, so the 3 repeats: 0.58333…

Exercise 4: Back to a fraction

Write 0.(36)0.(36) and 0.1(6)0.1(6) as fractions in lowest terms, and check with Fraction.

Answer

411\frac{4}{11} and 16\frac{1}{6}

Solution
x=0.3636…100x=36.36…99x=36x=3699=411y=0.1666…10y=1.666…100y=16.66…90y=15y=1590=16\begin{aligned} &x = 0.3636\ldots && 100x = 36.36\ldots && 99x = 36 && x = \frac{36}{99} = \frac{4}{11} \\ &y = 0.1666\ldots && 10y = 1.666\ldots && 100y = 16.66\ldots && 90y = 15 && y = \frac{15}{90} = \frac{1}{6} \end{aligned}
python · try it yourself
from fractions import Fraction as F
print(F(36, 99), F(15, 90))
print(float(F(4, 11)), float(F(1, 6)))
4/11 1/6
0.36363636363636365 0.16666666666666666

Test yourself

What does Python's round(4.5) return?

  1. 5
  2. 4
  3. 4.5
  4. Error

Which fraction has a repeating decimal?

  1. 38\frac{3}{8}
  2. 720\frac{7}{20}
  3. 225\frac{2}{25}
  4. 56\frac{5}{6}

What is 0.(81)0.(81) as a fraction in lowest terms?

  1. 81100\frac{81}{100}
  2. 911\frac{9}{11}
  3. 8190\frac{81}{90}
  4. 810\frac{8}{10}