Need Help with this code.. (VB.net)

Mykro

Newcomer
Joined
Aug 31, 2003
Messages
23
Location
Dana Point Ca.
What I'm trying to do is convert from Feet into inches, through code.. example: lets say I have 5.65' feet..
I know that I have 5' already.. so I need to convert the .65 to inches.So I multiply by 12 to get inches .65 x 12 = 7.8 " inches. I remove the 7 so now I have .8 inches. Now all I have to do is multiply by 8 to get 1/8th inches or 16 to get 1/6ths inches etc. etc.. Usually 1/8 inches is sufficient for what I need to do.. So.. 5.65 Feet converts to 5' 7 6/8" inches or 5' 7 3/4" What I can't seem to figure out is to do this in code.. I need a code guru to figure this one out.. I'm still to much of a novice at this point!..
Thanks..
 
How far have you gotten?

How much of this can you already do in code?
For the fractions of an inch part, all you really need to do is:
Round it to the nearest 8th or 16th by multiplying it by 8 or 16, as you stated, rounding the result to the nearest integer, then dividing it by 8 or 16 again.
At this point, you can check the number of digits in your result (you can convert it to string and then get its .Length)
Example:
0.5 has 3 characters, and you can represent this as 1/2, with 2 in denominator.
0.25 has 4, it is 1/4, with 4 in denominator.
0.125 has 5, it is 1/8, with 8 in denominator.
Before you do this, check if there is a decimal part by finding the IndexOf the "."c in the string. :)
It will cause problems if there are no fractions of the inch.
 
Back
Top