Working With Feet and Inches

# Thread: Working With Feet and Inches

1. Shawn Kern Guest

## Working With Feet and Inches

Is there a way to add and divide in feet and inches.<BR>Ex: 25Feet / 2 = 12feet 6inches ; 25Feet / 12feet 6inches = 2 ;<BR>12Feet 6Inches + 12Feet 6Inches = 25 Feet<BR>I really need help with this.<BR><BR>Thanks

2. Member
Join Date
Dec 1969
Posts
34

## RE: Working With Feet and Inches

"\" is integer division in vbscript<BR><BR>best thing to do is convert feet and inches to just inches, then convert back.<BR><BR>for example.<BR>feet1 = 32<BR>feet2 = 14<BR>inches1 = 10<BR>inches2 = 35<BR><BR>&#039;ADDITION EX.<BR><BR>total1 = (feet1 * 12) + inches1 &#039;convert to inches<BR>total2 = (feet2 * 12) + inches2 &#039;convert to inches<BR><BR>total = total1 + total2<BR><BR>totalfeet = total / 12 &#039;convert back to feet<BR>totalinches = total MOD 12 &#039;convert back to inches<BR><BR>response.write totalfeet&"ft.,"&totalinches&"in."<BR><BR><BR>&#03 9;DIVISION EX.<BR><BR>totalinches = (feet1 * 12) + inches1 &#039;convert to inches<BR>total = round(totalinches 2) &#039;divide and round<BR>totalfeet = total 12 &#039;convert back to feet<BR>totalinches = total MOD 12 &#039;convert back to inches<BR><BR>response.write totalfeet&"ft.,"&totalinches&"in."<BR>

3. Senior Member
Join Date
Dec 1969
Posts
614

## Try this for a start...

&#060;SCRIPT language="VBSCRIPT"&#062;<BR> function feetAdd(strOne,strTwo)<BR> ft1=getFeet(strOne)<BR> ft2=getFeet(strTwo)<BR> feet=ft1+ft2<BR> feetAdd= getFandI(feet)<BR> end function<BR><BR> function getFeet(strInput)<BR> x=instr(1,strInput,"&#039;")<BR> ft=(left(strInput,x-1))<BR> getFeet=ft+ (right(strInput,len(strInput)-x))/12<BR> end function<BR> <BR> function getFandI(lngFeet)<BR> feet=int(lngFeet)<BR> inches= cint(12*(lngFeet-feet))<BR> getFandI= cstr(feet) & "&#039; " & cstr(inches)<BR> end function<BR> <BR> <BR> alert feetAdd ("25&#039;6","30&#039; 5")<BR>&#060;/SCRIPT&#062;<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•