Converting Decimal Fractions

by Welopez

Note Bene: As has been discussed many times in the JB and LB forums, due to the way computers handle the conversion of binary values to floating point decimals, do not bet your life on decimal fractions beyond the 8th digit to the right of the decimal.

I prowl the JB and LB boards to get an idea what questions new users are asking, and hopefully find another subject for a new tutorial. It's surprising to me when some people ask how to convert decimal fractions, but there have been several questions lately.

Okay, Henry Handyman has decided to build a new carport. Before going to his home improvement center and buying a lot of 2x6's and other material, he has made a sketch of his project. Henry's carport will be 12 feet wide, 7 feet high at the sides, and have a gabled roof with a peak 3 feet higher than the sides. I don't know why he needs such a tall carport, Henry's only car is a 1972 Karmann-Ghia, but that's his plan. Henry remembers his middle-school math so he knows how to calculate the hypotenuse of a right triangle. His sketch looks like this:

Image

Henry wants to allow a 15 inch overhang on each side for the eaves. How long should the rafters be? (Length c = SQR(3^2 + 6^2) = 6.70820293 feet. Let's round that to 6.7082 and drop the final four digits, since the width of Henry's pencil lead will be more than 1/10,000th of an inch and he will not be able to draw a more accurate line.

      INPUT "Base? "; b  'the base is 1/2 the width of the car port
      INPUT "Height? "; h  'height of peak above length of side
      c=SQR(h^2+b^2)
      eave=1.25
      PRINT "Rafter length = "; c + eave  'total length of rafter
      END

Now Henry knows his rafter will need to be 6.7082 feet long, plus 1.25 feet (15 inches) to allow for the eave, total 7.9582 feet. Cool! A 10 foot length of 2x6 will be adequate for Henry's rafter... but how much should he measure for an exact length?

If Henry were using metric measurements, the decimal component of his rafter would be plainly shown on his tape measure. Since he is using feet and inches, he needs to multiply the fractional part to the right of the decimal of feet, times 12 inches, .9582 = 11.4984 inches. So far he knows the rafter length will be 7 feet, 11 and something inches, so let's multiply the fractional part of inches times 32, to obtain 32ths of an inch. 32 * .4984 = 15.9488/32ths of an inch. Henry can measure and cut his rafter to a length of 7 feet, 11 and 16/32 inches. 16/32 is 15.9488/32 rounded up; 16/32 is also 8/16, 4/8, or 1/2 an inch. Fractions are not difficult either.

Six months later, Henry has finished his weekend project and decides to take his Karmann-Ghia to the local dirt track for a spin. The dirt track is an irregular shape, somewhat resembling a capital letter D, but Henry does not know the length of the track. He notes his odometer reading at the starting line, makes a leisurely circuit of the track, and notes the odometer reading when he returns to the starting line, and learns the length of the dirt track is 3.4 kilometers. What?? Those confounded Europeans! How does he convert kilometers to miles? A helpful Worble whispered in Henry's ear, "Multiply kilometers by .6213699 to obtain miles."

      INPUT "Kilometers? "; km
      mi = km * .6213699  'convert km to miles
      ft=(mi - INT(mi))*5280  'multiply decimal fraction by 5280 feet per mile
      PRINT "The distance in miles is "; INT(mi); " and "; ft; " feet."
      END

Okay, 3.4km * .6213699 = 2.11265766 miles. Henry learns the dirt track is 2 and something miles around. Henry knows there are 5280 feet in a mile, so he can multiply the decimal fraction of the track length to obtain a more accurate figure, .11265776 * 5280 = 594.832445 feet. If Henry truly wants to get accurate, he can multiply the decimal fraction of feet by 12, to obtain inches. When Henry is all done, he has calculated the length of the dirt track to be 2 miles, 594 feet, and 9.98934 inches. He can really get silly and convert inches to fractions of an inch, but that would be a little much.

After a little work with decimal fractions, Henry has learned the value to the right of the decimal point, multiplied by the unit of measure yields the converted value.

Miles to feet, multiply decimal value by 5280

Feet to inches, multiply decimal value by 12

Inches to fraction, multiply decimal value by 4, 8, 16, 32, etc, to obtain 4ths, 8ths, 16ths, 32ths.

If you're unit of measure is statute miles, astronomical units, tons, yards, or any other type of measure, the method is the same. Cast off the integer value of your answer and multiply the decimal value times the smaller unit of measure. Miles, feet, and inches may not be as simple as moving the decimal point in metric units, but conversions are easily done