PDA

View Full Version : [SOLVED:] converting gram to lbs vba - two decimals after point requirement



sarveshspace
08-20-2018, 02:19 PM
hello,
I would like to convert the weight in grams typed in by the user in lbs . I would like it rounded to two decimal places after zero and if the value in lbs is less than one lb ,then i would like the no to begin with a single zero example 0.41 lbs.

I have this code

'1


'setting weight of item in grams
Dim wt1 As Range
Set wt1 = ActiveDocument.Bookmarks("wt1").Range
wt1.Text = Me.TextBox3.Value
'converting weight to lbs
Dim convert As Double
convert1 = Val(wt1) * 0.0022
convert1 = Format(convert1, "####.##")
Dim lb1 As Range
Set lb1 = ActiveDocument.Bookmarks("lb1").Range
lb1 = convert1

however, i do not get the zero before decimal if value of weight is less than 1 lb.
Thank you for your help!

macropod
08-20-2018, 04:26 PM
convert1 = Format(convert1, "0.00")