The algorithm arises from a comment on GameDev.net by user John Bolton.
Here is an algorithm for converting a value to the closest fraction (given a maximum value for the denominator). It is based on Farey Sequences. It is probably much faster than finding GCDs and the results are much more useful. For example, using the suggestions above, .333333 will be converted to 333333/1000000, which is probably not what you want. Using this algorithm, you will get 1/3.
Objective-C/Swift Rational class
An extension for floating point values to return the rational components for that value
Notes
The algorithm arises from a comment on GameDev.net by user John Bolton.
Click here to see original post