Rounding fractions with less digits

52 Views Asked by At

The problem

I'm trying to round a fraction $\frac{a}{b}$ taking away digits from one or both integers. Let's say a or b have 3 digits, and I want a new $\frac{a'}{b'}$ with as much as 2 digits for each a and b, and the least rounding-error.

Examples:

  • $\frac{5}{198} \approx \frac{3}{99}$

Here I divide both by 2, because that way I get 99 as b', which is the greatest number b' can be. Seems to be the best approximation.

  • $\frac{469}{327} \approx \frac{99}{69} = \frac{33}{29}$

Here I did the same trick. I divided both numbers by $\frac{max(a,b)}{99}$ and then round them to get the bigger integers. I'm not so sure this is the best rounding I can make with 2 digits. Still better than $\frac{round(a/10)}{round(b/10)}$

original = $\frac{469}{327} = 1,434250765$
$\frac{Round(\frac{a*99}{max(a/b)})}{Round(\frac{b*99}{max(a/b)})} = \frac{33}{23} = 1,434782609$
$\frac{Round(\frac{469}{10})}{Round(\frac{327}{10})} = \frac{47}{33} = 1,424242424$

Is there a better method to do this?

1

There are 1 best solutions below

3
On BEST ANSWER

The optimal way is to first express your original number as a continued fraction. For example, $$\frac{469}{327}=[1;2,3,3,3,4]\approx 1.434251$$

Then, to get an approximation with smaller numbers in the fraction, just drop one or more of the last terms, and recompute from that continued fraction. For example, $$[1;2,3,3,3]=\frac{109}{76}\approx 1.43421$$ $$[1;2,3,3]=\frac{33}{23}\approx 1.4348$$ $$[1;2,3]=\frac{10}{7}\approx 1.4286$$ $$[1;2]=\frac{3}{2}=1.5$$

These approximations are called continuants, and are known to be the best possible approximations to the original number, with that denominator or lower. For example, if you want a denominator of $76$ or less, you can't do better in approximating $\frac{469}{327}$ than $\frac{109}{76}$.


Additional comments:

  1. You can do this if the original number is irrational, too; you just get an infinite continued fraction instead of a finite one.

  2. To find the terms, you iteratively (a) take the floor; (b) subtract that floor and take the reciprocal. For example, $\lfloor \frac{469}{327} \rfloor=\color{blue}1$. $\frac{1}{\frac{469}{327} - 1}=\frac{327}{142}$. $\lfloor \frac{327}{142}\rfloor=\color{red}2$. Continue to get $[\color{blue}1;\color{red}2,3,3,3,4]$.

  3. Wolfram Alpha can easily find both the continued fraction for a number, and go back from the (modified) continued fraction back to a fraction.