Optimized algorithm for converting a decimal to a “pretty” fraction
问题 Rather than converting an arbitrary decimal to an exact fraction (something like 323527/4362363), I am trying to convert to just common easily-discernible (in terms of human-readability) quantities like 1/2, 1/4, 1/8 etc. Other than using a series of if-then, less than/equal to etc comparisons, are there more optimized techniques to do this? Edit: In my particular case, approximations are acceptable. The idea is that 0.251243 ~ 0.25 = 1/4 - in my usage case, that's "good enough", with the