How to extract fraction from a floating point number I'm making some tests with float type (floating point number) with programming and in some of my tests I need to extract the fraction that originates the float value.
Let $ x $ be a floating point number, and $ a, b \in \mathbb{Z} $, where $ x \approxeq \frac{a}{b} $, I want to discover $ a $ and $ b $.
e.g., if I have $ 0.5 $, I need a method (maybe numerical?) that gives me $ \frac{1}{2} $ or some of its multiples.
If there's more than one method, I would like the fastest or simples to implement with a programming languagg.

Let $P=10^n$ where $10^{-n}$ denotes the precision of the floating point number. Compute the greatest common divisor of $G=Gcd(P\cdot F,P)$, where $F$ is the floating point number. 
Then the answer is $\displaystyle\frac{F/G}{P/G}$.
