## Ruby, <s>127</s> 125 bytes

    b=r if(r=(q*d-=1).round.to_r/d).round(p).to_f.to_s==n while d>1

Defines a function `f` which returns the result as a `Rational`. E.g. if you append this code

    p f["1.7"]
    p f["0."]
    p f["0.001"]
    p f["3.1416"]

You get


The loop is over denominators. I'm starting with the full fraction, e.g. `31416/10000` for the last example. Then I'm decrementing the denominator, proportionally decrement the numerator (and round it). If the resulting rational rounds to the same as the input number, I'm remembering a new best fraction.