Let’s say we have 0.33, we need to output 1/3.
If we have 0.4, we need to output 2/5.
The idea is to make it human-readable to make the user understand ‘x parts out of y‘ as a better way of understanding data.
I know that percentages is a good substitute but I was wondering if there was a simple way to do this?
I have found David Eppstein’s find rational approximation to given real number C code to be exactly what you are asking for. Its based on the theory of continued fractions and very fast and fairly compact.
I have used versions of this customized for specific numerator and denominator limits.