• Status: Solved
• Priority: Medium
• Security: Public
• Views: 852

# ASP - Converting Inches to Feet with Inches

I would like to get some help working out a formula to obtain the feet - inch value based on a inch value.

Example:

If I have a value of 244 inches

I would like to convert it to 20 feet .333 inches (rounding up/ down the inches value would be great)

and then save each calculated value to a separate record set field like:

rsData("BoxLength_Feet") = 20
rsData("BoxLength_Inch") = .333

I hope this is not much trouble but I really need the help.

Thank you very much.
0
metropia
• 6
• 5
• 2
4 Solutions

Author Commented:
I found this code online:

string feet = int.parse(44/12).ToString("n0") + " ft."; // Divide by 12 inches and remove the decimal

string inches = int.parse(44%12).ToString() + " in." // Get the remainder of the division of 12 for the inches

but I think that is using vb.net or C# and I am using classic asp with vbscript. Maybe I could get help converting the code to this version of ASP?

Thank again!
0

Commented:
dim TotalInches = 44
dim feet = cint(TotalInches/12)
dim inches = cint(TotalInches MOD 12)
0

Author Commented:
hi strickdd,

let me give that a try.

thanks!
0

Author Commented:
i see it works partially.

the only problem so far i have seen is that if i have a value of 11 inches

then i get this on each field:

rsData("BoxLength_Feet") = 1
rsData("BoxLength_Inch") = 11

that is wrong, right?

in this case 11 inch = 0.916 feet

so the values in this case should be:

rsData("BoxLength_Feet") = 0
rsData("BoxLength_Inch") = 11

there is another example

when the inches are 18

rsData("BoxLength_Feet") = 2
rsData("BoxLength_Inch") = 6

i think 18 inches = 1 feet .5 inches

this is how i implemented the code:

these 3 variables contain the original inches values for the calculation.
BoxLength
BoxWidth
BoxHeight
rsData("BoxLength_Feet") = cint(trim(request.form("BoxLength"))/12)
rsData("BoxLength_Inch") = cint(trim(request.form("BoxLength")) MOD 12)

rsData("BoxWidth_Feet") = cint(trim(request.form("BoxWidth"))/12)
rsData("BoxWidth_Inch") = cint(trim(request.form("BoxWidth")) MOD 12)

rsData("BoxHeight_Feet") = cint(trim(request.form("BoxHeight"))/12)
rsData("BoxHeight_Inch") =cint(trim(request.form("BoxHeight")) MOD 12)

0

Commented:
Try this, haven't tested it here.

rsData("BoxLength_Feet") = int(cint(trim(request.form("BoxLength")))/12)
rsData("BoxLength_Inch") = cint(trim(request.form("BoxLength"))) MOD 12

~bp
0

Commented:
I believe this is probably because the cint() function rounds up automatically. Try this:

dim feet = int(TotalInches/12)
0

Author Commented:
billprew:

if working witht the following test values:

BoxLength = 244 in
BoxWidth = 21 in
BoxHeight = 15 in

rsData("BoxLength_Feet") = cint(trim(request.form("BoxLength"))/12)
rsData("BoxLength_Inch") = cint(trim(request.form("BoxLength")) MOD 12)

rsData("BoxWidth_Feet") = int(cint(trim(request.form("BoxWidth")))/12)
rsData("BoxWidth_Inch") = cint(trim(request.form("BoxWidth"))) MOD 12

rsData("BoxHeight_Feet") = int(cint(trim(request.form("BoxHeight")))/12)
rsData("BoxHeight_Inch") = cint(trim(request.form("BoxHeight"))) MOD 12

Results:

BoxLength_Feet = 20
BoxLength_Inch = 4

BoxWidth_Feet = 1
BoxWidth_Inch = 9

BoxHeight_Feet = 1
BoxHeight_Inch = 3

It looks much better and accurate, but I still have a doubt.

http://www.onlineconversion.com/length_common.htm

tells me that an inch value of 21 should be equal to 1.75 feet and an inch value of 15 shoud be 1.25 feet.

why the calculation leave respectively me with

(21 inches)
BoxWidth_Feet = 1
BoxWidth_Inch = 9

(15)
BoxHeight_Feet = 1
BoxHeight_Inch = 3

I am not complaining at all. I appreciate your help. I just want to know why the differences.

Thank you so much.
0

Commented:
Any maybe just a small amount simpler (not the use of the \ for integer division)...

``````rsData("BoxLength_Feet") = cint(trim(request.form("BoxLength"))) \ 12
rsData("BoxLength_Inch") = cint(trim(request.form("BoxLength"))) MOD 12
``````
0

Commented:
Not sure I understand you followup question.  Are you trying to convert inches to feet and inches (that's what it seemed like) or just feet using a decimal number?

there are 12 inches in a foot, so in your example of 21 inches, it is 1 foot (12 inches) with another 9 inches remaining.  Which is the same as 1.75 feet, since 9/12 = .75.

~bp
0

Author Commented:
Thank you for the explanation. I apologize for my ignorance.
0

Commented:
No need to apologize, there are no bad questions, hope that helped.

~bp
0

Author Commented:
Thank you both of you guys.

I tried my best to split the points fairly.

I ended up using bill's solution, but did not want to omit strickdd's recommendation either.

Best regards.
0

Commented:
Welcome.

~bp
0

## Featured Post

• 6
• 5
• 2
Tackle projects and never again get stuck behind a technical roadblock.