Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Need help with how I could convert a fraction with a decimal to one that has only whole numbers.?
Writing a little program to format fractions first then utilize them in another program that functions as a mixed number/fraction calculator.
I got most of it done but and got this portion working actually but it does seem redundant.
So for example, it would convert "4.2/2" to 21/10.
Initially, I multiply both numerator and denominator component by 1000 then just cast both numbers as integer types.
It works but I feel like there'd be a better way. Also occasionally a large denominator might appear that would render the ( x 1000) step useless.
Any thoughts or algorithms I should look up?
1 Answer
- ChrisLv 74 years ago
To brute-force this, just multiply numerator and denominator by the same number, starting from 2, until both are integers.
In the above example, you'd only have to go up to 5.
Another way is to multiply both by 10,000,000,000, cut off remaining decimals, then calculate the greatest common divisor and divide both by that.