Visual Basic format functions

knowing that:

Format Percent (0.185, 2) will out put 18.50%

if i have the following partial code:

Dim food, calories, grams As String
Dim Fact_Calories, Answer As Double

Fact_Calories = grams * 9
        Answer = Fact_Calories / calories

how can I format this Answer variable to the percent fortmat mention above
LVL 1
jsctechyAsked:
Who is Participating?
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.

bobbit31Commented:
Format(Answer*100, "#0.00%")
0
jsctechyAuthor Commented:
it prints 0.00% and I want 00.00%, meaning 12.00%
0
bobbit31Commented:
Format(Answer*100, "00.00%")

;)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jsctechyAuthor Commented:
for some reason if the result is 35.70% it prints 35.7% but i need the zero also in the out put

Thanks
0
bramsquadCommented:
it shouldnt

MsgBox(Format(0.357, "00.00%"))

returns this

35.70%

0
jsctechyAuthor Commented:
knowing the number yes but using the variable will print out 35.7% and I need 35.70

Here is the whole code:
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim food, calories, grams As String
    Dim Fact_Calories, Answer, Answer1 As Double
Sub Input()
        food = txtfood.Text
        calories = CDbl(txtCalories.Text)
        grams = CDbl(txtGrams.Text)
    End Sub
    Sub output()
        lstOutput.Items.Clear()
        lstOutput.Items.Add(food & "Contains " & cal() & "% Calories from fat.")
        lstOutput.Items.Add(food & "if statement ")
    End Sub
    Function cal() As Double
        Fact_Calories = grams * 9
        Answer = Fact_Calories / calories * 100
        Format(Answer, "00.00%")
        Return Answer
    End Function

    Private Sub cmdCompute_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCompute.Click
        Input()
        output()
    End Sub
End Class
0
bobbit31Commented:
Sub Command1_Click()
  msgbox   Format(cal, "00.00%")
end sub

Function cal() As Double
        Fact_Calories = grams * 9
        Answer = Fact_Calories / calories * 100
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
qing02051981Commented:
Should this give u percentage in two decimal places?
Format Percent (Answer, 2)
0
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.