This code is written in reduceFraction method of the attached class. For this we determine the greatest common divisor(gcd) of numerator and denominator and divide numerator and denominator (from Step 3) to get the fraction in lowest terms. Now we only need to reduce it to its lowest terms.For example, if the number entered was 2.45, then our algorithm till this step will give us 245/100. This gives us the numerator and denominator parts of our fraction.Multiply and divide the given number with 1000. Example, if we have 3 digits right of decimal point. Step 2: Let us suppose the number of digits to the right of decimal be p. Now the numerator can be determined by multiplying the part of the number before decimal (first element of array from Step 2) by the denominator determined in the previous step and adding the part of the number after decimal (second element of array from Step 2). The method of how to convert a decimal to a fraction are given below: Step 1: Count the number of digits to the right of the decimal point. This will give us the denominator of the fraction. This will be the lenngth of second element of the array in Step 2. Convert the decimal number 5.066 into a fraction. Because the both the numerator and denominator have a common factor, then the fraction can be simplified to the lowest terms: 5/100 1/20. multiply 10 by the length of digits after decimal. Since 10 2 is the same as 10 x 10 100, the write the number in fractional form: 5/100. To remove the decimal, we need a multiplier of 10 with zeroes equal to the number of digits after the decimal.One will be the numerator and other will be denominator. Subsequently, question is, what is 2.875 on a ruler The length value 2.875 in (inch) in words is 'two point eight seven five in (inch)'. Designed with simplicity, usability and beauty in mind FEATURES: - Elegant & Intuitive interface - Decimal to fraction converter - Fraction to decimal. Use the answer as the top of the fraction. Read the fraction number as a string using Scanner class. Then, multiply the decimal by the fraction you desire and round off the answer to the nearest whole number. Transforming a distance in its decimal form to its fraction inches is almost the same as converting any decimal to a regular fraction.Almost.Be sure to print it out and keep it close by when you are working on problems that require you to convert decimals to fractions or vice versa. Import import public class Fraction Ībove program when executed gives the following result You can use the decimal and fraction chart above as a reference to quickly make conversions between decimals and fractions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |