Question
Approximate decimal to fraction. /** * Constructor - HD Level(20 marks) * * @param dec * :double - The decimal to approximate * * Write
Approximate decimal to fraction. /** * Constructor - HD Level(20 marks) * * @param dec * :double - The decimal to approximate * * Write an algorithm which finds an approximation of the fractional form of a decimal. * * Set the instance parameters to the numerator and denominator found in the approximation. * * You may assume that d is a positive number with only 2 decimal places. * * Your approximation must be correct to 2 decimal places. * * Hint: * * There are many ways to do this, but there is one very easy approach * which cannot be found on the internet. * * Examples: * * 0.333 -> 1/3 * * 0.25 -> 1/4 * * 0.66 -> 2/3 * * 0.67 -> 19/28 * * 5.78 -> 81/14 * * 5.75 -> 23/4 * */ public Fraction(double dec) {
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started