Solved

# ASP - Converting Inches to Feet with Inches

Posted on 2011-10-18
802 Views
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
Question by:metropia

Author Comment

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

LVL 28

Assisted Solution

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

Author Comment

hi strickdd,

let me give that a try.

thanks!
0

Author Comment

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

LVL 51

Expert Comment

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

LVL 28

Assisted Solution

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

dim feet = int(TotalInches/12)
0

Author Comment

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

LVL 51

Accepted Solution

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

LVL 51

Assisted Solution

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 Comment

Thank you for the explanation. I apologize for my ignorance.
0

LVL 51

Expert Comment

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

~bp
0

Author Closing Comment

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

LVL 51

Expert Comment

Welcome.

~bp
0

## Featured Post

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…