Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a function for turning any number $x$ into a fraction with a denominator that has a maximum of $k$ digits? (I'm sure there is, since Excel has one built in, I just can't figure out what it is.)

For example, $f(0.1234) = $

  • $\frac{106}{859}$ where $k=3$;
  • $\frac{10}{81}$ where $k=2$;
  • $\frac{1}{8}$ where $k=1$.
share|cite|improve this question
A reasonably good answer can be found from the continued fraction expansion of $x$. – André Nicolas Aug 9 '13 at 22:39
I would call the continued fraction answer the best answer, in certain quantifiable ways. @AndréNicolas – Thomas Andrews Aug 9 '13 at 22:43
One could complicate things by looking at secondary convergents, but there is probably no point. – André Nicolas Aug 9 '13 at 22:48
For example, the continued fraction expansion for $0.1234$ yields convergents $0,1/8,9/73, 10/81, 19/154, 29/235, 106/859, 135/1094, 241/1953, 376/3047, 617/5000=0.1234$. – Thomas Andrews Aug 9 '13 at 22:53
@AndréNicolas, would you like to make that comment into an answer? – Joe Apr 13 '15 at 19:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.