given a ratio (ex. 374:266 or 724.36292:740.37872) how do I get the smallest ratio? 187:133 for the first ex. Now for the second ex, that is a tricker answer. Do I convert to integer and then calculate the smallest ratio? I think I am leaning that way.
Also, 187:133 seems a bit large. Next question is how to identify a smaller ratio that is "close"? say within 2 or 3 decimal places? this example ratio is about 1.4060:1 or I guess I could say 14.06:10 then about 7:5? Not sure if I'm even close to the right track on this.
Be nice if there were already a gem that did this calculation. But I can write a method once I find a correct algorithm. I've tried google searching, but keep getting either web pages that do a Ratio Simplifier or things about gem stone ratios.
NOTE: this is not for Rails. It is for a process that I'm writing. Will be ran on my mac locally only.
Sometimes the hardest part is finding the right terms to search for.
The numerator and denominator of an irreducible fraction are relatively
coprime.
Down the wikipedia rabbithole:
Xavier's reply saved my evening.
After relearning that Floats and Rationals don't mix well. Fixed decimal to
the rescue...
Sometimes the hardest part is finding the right terms to search for.
The numerator and denominator of an irreducible fraction are relatively
coprime.
Down the wikipedia rabbithole: Coprime integers - Wikipedia Irreducible fraction - Wikipedia Euclidean algorithm - Wikipedia
Xavier's reply saved my evening.
After relearning that Floats and Rationals don't mix well. Fixed decimal
to the rescue...