Link to home
Start Free TrialLog in
Avatar of metropia
metropiaFlag for United States of America

asked on

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.
Avatar of metropia
metropia
Flag of United States of America image

ASKER

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!
SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi strickdd,

let me give that a try.

thanks!
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)      


Thank  you for your help.


Avatar of Bill Prew
Bill Prew

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
billprew:

if working witht the following test values:

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

after applying your calculation:

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.

the converter on this page:

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the explanation. I apologize for my ignorance.
No need to apologize, there are no bad questions, hope that helped.

~bp
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.
Welcome.

~bp