Continued fraction
Best rational within an interval

A rational that falls within the interval (x, y), for 0 < x < y, can be found with the continued fractions for x and y. When both x and y are irrational and

where x and y have identical continued fraction expansions up through a, a rational that falls within the interval (x, y) is given by the finite continued fraction,

This rational will be best in the sense that no other rational in (x, y) will have a smaller numerator or a smaller denominator.

If x is rational, it will have two continued fraction representations that are finite, x and x, and similarly a rational y will have two representations, y and y. The coefficients beyond the last in any of these representations should be interpreted as +∞; and the best rational will be one of z (x, y), z (x, y), z (x, y), or z (x, y).

For example, the decimal representation 3.1416 could be rounded from any number in the interval [ 3.14155, 3.14165). The continued fraction representations of 3.14155 and 3.14165 are

and the best rational between these two is

Thus, 355 / 113 is the best rational number corresponding to the rounded decimal number 3.1416, in the sense that no other rational number that would be rounded to 3.1416 will have a smaller numerator or a smaller denominator.
punctuation:no_comma