To solve this problem (in one of my projects), I took the following steps:
- Built a dictionary of decimal/fraction strings.
- Wrote a function to search the dictionary for the closest matching fraction depending on the "decimal" part of the number and the matching criteria.