Calculating 2 whole factors from a fraction

298 Views Asked by At

I've been out of school for a very long time, and can't wrap my head around calculating 2 whole numbers from a fraction. For instance, if I have 2 ratios --

4:3    1.33333...
16:9   1.77777...
?:?    (automatically generated)

I want to be able to look up the whole number representations from a decimal point.(for a software program) I think there should be a fairly easy way to do this? I've seen some other questions possibly linked to this, however, I can't read math anymore either, so text answers would be wonderful :)

2

There are 2 best solutions below

1
On BEST ANSWER

There's a straightforward algorithm for this. Allow me to demonstrate on

$$ 0.1\overline{37} = 0.1373737373737\ldots$$

The first step is to split off the non-repeating part:

$$ 0.1\overline{37} = 0.1 + 0.0\overline{37} $$

then you pull out the 'common factor' from the repeated part

$$ 0.1\overline{37} = 0.1 + 37 \cdot 0.0\overline{01} $$

then you multiply and divide by an appropriate number to make the repeated part all 9's

$$ 0.1\overline{37} = 0.1 + \frac{37}{99} \cdot 0.0\overline{99} $$

then you simplify repeated 9's:

$$ 0.1\overline{37} = 0.1 + \frac{37}{99} \cdot 0.1 $$

with practice you can do all of the above in a single step. Once here, you can simplify further if you need to

$$ 0.1\overline{37} = \frac{1}{10} + \frac{37}{99} \cdot \frac{1}{10} = \frac{68}{495} $$


If you need to do this in software rather than by hand, this is an example of the "rational reconstruction" problem, and some languages have solutions built-in. e.g. in python, you can use the fractions module:

>>> from fractions import Fraction
>>> Fraction('0.13737373737').limit_denominator()
Fraction(68, 495)

although it takes some care to ensure that you get the right make sure you get it right. e.g. the default settings would give the wrong answer if I just used '0.1373737'.

The general algorithm is continued fractions, and it will work even when the part you have doesn't repeat, assuming you give enough information. The python example I mention above uses this method (I believe), and it can recover the fraction $1/7$ from a decimal approximation:

>>> Fraction('0.1428').limit_denominator(100)
Fraction(1,7)
4
On

You can compute it. Multiply the decimal by $10^n$, where $n$ is the number of digits in the repeat of the decimal and subtract. Example: given $ x=5.181818\ldots \\100x=518.1818\ldots,\\99x=513,\\x=\frac{513}{99}$