# convert decimal hundredths to feet and inches (vb.net - 2008 - windows form)

i am working on a project that has height and its in decimal hundredths form i need it to be feet and inches

heres what i got so far
it should return 6.6 from 90 but i get
PackageDimensions.Height: 90
PackageDimensions.Height - inches: 7.50

``````Try         ' read PackageDimensions.Height
Result_Box.AppendText("PackageDimensions.Height: " & item.ItemAttributes.PackageDimensions.Height.Value & vbCrLf)
Dim b_height As Decimal = Format((item.ItemAttributes.PackageDimensions.Height.Value / 12), "#.00")
Result_Box.AppendText("PackageDimensions.Height - inches: " & b_height.ToString & vbCrLf)
Catch ex As Exception
textboxauth.Text = "Error reading PackageDimensions.Height: " & ex.ToString()
End Try
``````
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manager / Technology SpecialistCommented:
It's exacly the same as answered here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_25573307.html?cid=1131#a28895571

but the convertion now is:

1 foot = 12 inches
Manager / Technology SpecialistCommented:
If you need the formulas you have:

1 - 12
ft - inch

feet = inches / 12
inches = feet * 12
Author Commented:
Dim b_height As Decimal = FormatNumber(CStr(CDbl(((item.ItemAttributes.PackageDimensions.Weight.Value) / 100) * 12)), 2)
returns
PackageDimensions.Height: 90
PackageDimensions.Height - inches: 2.40

im still not getting it right tho

Commented:
Erm,

90 / 12 = 7.50

The answer you are getting is correct, and so is your code mate.

:)
Commented:
>it should return 6.6 from 90 but i get

Are you sure? I think you mean 7.6!

Try this code

Dim Height As Integer = 90
Dim Divider As Integer = 12
Dim Feet As Integer
Dim Inches As Integer
Feet = Math.DivRem(Height, Divider, Inches)
Debug.Print(String.Concat(Feet, ".", Inches))
Commented:
Aaaah!

You want it displayed as 7 feet 6 inches, not 7.5 feet!

Try this code formula :

numbervar inches :=90;

ToText(int(inches/12),0,"")  & "' " & totext(remainder(inches,12),0) & '"'
Commented:
>ToText(int(inches/12),0,"")

Are you sure it wont round it? 7.6->8?
Author Commented:
hrrm somethings wrong in denmark then.. its a book im trying to do.

the book is 6 and 3/4 inches
amazon says its 6.6
Product Dimensions: 6.6 x 4.1 x 0.9 inches

im getting the data from amazon so the hundredths of a inch of 90 is from them

i hate math i got a headache.

i need to go to a Sunday engagement ill be back in a few hours
thanks for all the help so far

Author Commented:
i have the physical book too
Author Commented:
ill be back in a few hours
Author Commented:
still not right on dimensions

amazon says one thing im getting totally different info

PackageDimensions.Weight: 44
PackageDimensions.Weight-oz: 7.04oz
PackageDimensions.Height: 94
PackageDimensions.Height - inches: 7.83
PackageDimensions.Length: 772
PackageDimensions.Length - inches: 64.33
PackageDimensions.Width: 504
PackageDimensions.Width - inches: 42.00

``````Try         ' read PackageDimensions.Height
Result_Box.AppendText("PackageDimensions.Height: " & item.ItemAttributes.PackageDimensions.Height.Value & vbCrLf)
Dim b_height As Decimal = FormatNumber(CStr(CDbl(((item.ItemAttributes.PackageDimensions.Height.Value) / 12))), 2)
Result_Box.AppendText("PackageDimensions.Height - inches: " & b_height.ToString & vbCrLf)
Catch ex As Exception
textboxauth.Text = "Error reading PackageDimensions.Height: " & ex.ToString()
End Try
Result_Box.AppendText("PackageDimensions.Length: " & item.ItemAttributes.PackageDimensions.Length.Value & vbCrLf)
Dim b_Length As Decimal = FormatNumber(CStr(CDbl(((item.ItemAttributes.PackageDimensions.Length.Value) / 12))), 2)
Result_Box.AppendText("PackageDimensions.Length - inches: " & b_Length.ToString & vbCrLf)
Catch ex As Exception
textboxauth.Text = "Error reading PackageDimensions.Length: " & ex.ToString()
End Try
Result_Box.AppendText("PackageDimensions.Width: " & item.ItemAttributes.PackageDimensions.Width.Value & vbCrLf)
Dim b_Width As Decimal = FormatNumber(CStr(CDbl(((item.ItemAttributes.PackageDimensions.Width.Value) / 12))), 2)
Result_Box.AppendText("PackageDimensions.Width - inches: " & b_Width.ToString & vbCrLf)
Catch ex As Exception
textboxauth.Text = "Error reading PackageDimensions.Width: " & ex.ToString()
End Try
``````
Commented:
I wouldl think that amazon is just dividing the inches by 12 so that 90 is 7.5 feet. Feet and inches are not separated by dot. Feet and dots are represented differently. Similarly for times, 90 mintues is 1.5 hours!
Author Commented:
if you look at the links its a paperback book... ever see a paperback book at 7.5 feeet???

somethings wrong with the calc. there are two books links both cant be that far off.

this is why im asking for help i couldn't figure it out
Commented:
What do you think 94 is then? It would be cm probably.
Author Commented:
this is the link to the book
http://www.amazon.com/Safety-Incentives-Recognition-Programs-Compliance/dp/1890966533/ref=sr_1_1?ie=UTF8&qid=1269883064&sr=8-1

amazon returns this in xml format

Wayne G. Pardy
Paperback
9781890966539
Reprint
1890966533

5995
USD
\$59.95

185

900
75
130
600

Book
1999-05-19
Safetycertified.Com Inc
Safety Incentives: The Pros and Cons of Award and Recognition
Programs (Osha Compliance)

we are trying to convert this area

900
75
130
600

this is what amazons page says about book dimensions
Product Dimensions: 9 x 6 x 0.8 inches
Shipping Weight: 1.3 pounds

so if we do our calc it should be in fact
9 inches high
7.5 inches wide
6 inches thick

man thats a hefty paperback book

somethings wrong here dunno what

Commented:
><Height Units="hundredths-inches">900</Height>

equals
900/100 = 9 inches

><Width Units="hundredths-inches">600</Width>

equals
600/100 = 6 inches

><Length Units="hundredths-inches">75</Length>

equals
75/100 = 0.75 inches = 0.8 inches

so you are probably looking at them the long way or the amazon is naming the dimensions differently.

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
so all i do is divide by 100 and round to .#
???

FormatNumber(CStr(CDbl(((item.ItemAttributes.PackageDimensions.Length.Value) / 100))), 2)
Manager / Technology SpecialistCommented:
This dimensions are of something similar to an A4 sheet area and a finger thick.
I don't know what kind of scrambling you guys are doing but this is plain simple.

900 hundreds of inches = 9 inches  (height)
75 hundreds of inches = 0.75 inches (lenght)
600 hundreds of inches = 6 inches (width)
130 hundreds of inches = 1.3 inches (weight)

on the webpage of the book we can read 9 x 6 x 0.8 inches
so what we see is that Amazon is rounding up the lenght to 0.8 the real 0.75 value.

Now... what's the problem exactly?
Commented:
>130 hundreds of inches = 1.3 inches (weight)

Never knew weight is expressed in inches as well.

We are confused why thickness is being referred to as length.
Author Commented:
yeah there fields are messed up

PackageDimensions.Weight: 130
PackageDimensions.Weight-oz: 20.80oz
PackageDimensions.Weight-lbs: 1.30lbs
PackageDimensions.Height: 75
PackageDimensions.Height - inches: 0.75
PackageDimensions.Length: 900
PackageDimensions.Length - inches: 9.00
PackageDimensions.Width: 600
PackageDimensions.Width - inches: 6.00

Product Dimensions: 9 x 6 x 0.8 inches
Shipping Weight: 1.3 pounds
i can live with the rounding of thick (not sure how to do that right now in vb.net(will look it up)

i get it
length = tall
width =  wide
height = thick

Commented:
>not sure how to do that right now in vb.net

For rounding, use the Math.Round function

Match.Round(0.75, 1)
Manager / Technology SpecialistCommented:
For roundings use the System.Math.Round
http://msdn.microsoft.com/en-us/library/zy06z30k.aspx
Author Commented:
ok now who the heck answered this..

400 points - ID: 29002645 CodeCruiser: for the /100

100 points - AlexCode: for pointing out im dumb and had it all along, and the reason for the fields being the way they are

sound about right? (i like to be fair)
Commented:
I am ok with it.
Manager / Technology SpecialistCommented:
fair mate... the important is you getting it right! :)

cheers!
Author Commented:
PackageDimensions.Weight: 130
PackageDimensions.Weight-oz: 20.80oz
PackageDimensions.Weight-lbs: 1.30lbs
PackageDimensions.Height: 75
PackageDimensions.Height - inches: 0.8
PackageDimensions.Length: 900
PackageDimensions.Length - inches: 9.00
PackageDimensions.Width: 600
PackageDimensions.Width - inches: 6.00

one last thing please how do i get the 9.00 and 6.00 to be a whole number but show .# if needed ie

9.0 = 9
and 9.3 = 9.3?
NO 0 on 9.0 if its got one?
I know this is a different question but then i got this all wrapped up unless u all really want me to ask another question

and thx on the solution and the post points award too

Commented:
You would have to use multiple variables to hold the value. How would you use this? Would you be just showing the value on UI?
Author Commented:
thanks for hanging in there trying to figure this out
Author Commented:
im gonna open a  new question for this brb with the link
Manager / Technology SpecialistCommented:
Try formating the value as:

.ToString("0.##")
Author Commented:
Author Commented:
that did it
alexcode

PackageDimensions.Weight: 130
PackageDimensions.Weight-oz: 20.80oz
PackageDimensions.Weight-lbs: 1.30lbs
PackageDimensions.Height: 75
PackageDimensions.Height - inches: 0.8
PackageDimensions.Length: 900
PackageDimensions.Length - inches: 9
PackageDimensions.Width: 600
PackageDimensions.Width - inches: 6

go post on other question ill award the points thanks again
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.