We need to convert the calculated value, which can be something like 3.33333000540733337 - 3 1/3. Any of the libraries I've tried, such as https://github.com/peterolson/BigRational.js , will convert this to the most accurate rational number, while I'm only interested in the approximate rational number, up to .01 significant decimal places.
In ruby, we are currently doing Rational (1.333) .rationalize (Rational (0.01)), which gives us 1 integer, 1 is the numerator, and 3 is the denominator.
Any thoughts on an algorithm that could help would be great.
source
share