Fuzzy rounding for Rationals

Is there an easy way to convert 0.005 to a Rational 1//200 ?
I guess 0.005 has no exact representation in base 2, which is why it is interpreted as this terribly long fraction.

EDIT: Actually my use case is more “general” than the above example.
I have a float which is the result of an Integer division where both arguments have ‘few’ digits (probably less than 6 in general). A better example is Rational(43/550). I.e. given 0.07818181818181819 I would like to obtain 43 and 550.

julia> a = Rational(1,200); b = Rational(0.005); iszero(float(a)-float(b))
true

julia> a
1//200

julia> b
5764607523034235//1152921504606846976

It is clear to me that trunc(Int, 1/0.005) == 200. Please consider the other example

See the rationalize function:

julia> rationalize(0.005)
1//200

julia> rationalize(43/550)
43//550
4 Likes

Thanks!