[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Visual Basic format functions

Posted on 2004-10-22
8
Medium Priority
?
199 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:jsctechy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 12381804
Format(Answer*100, "#0.00%")
0
 
LVL 1

Author Comment

by:jsctechy
ID: 12382252
it prints 0.00% and I want 00.00%, meaning 12.00%
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 12382273
Format(Answer*100, "00.00%")

;)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jsctechy
ID: 12382785
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
 
LVL 8

Expert Comment

by:bramsquad
ID: 12383012
it shouldnt

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

returns this

35.70%

0
 
LVL 1

Author Comment

by:jsctechy
ID: 12383555
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
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 12383877
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
 
LVL 1

Expert Comment

by:qing02051981
ID: 12389233
Should this give u percentage in two decimal places?
Format Percent (Answer, 2)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question