[RESOLVED] Format variable as percentage?
I'm fairly new to Visual basic, I'm taking an intro class on it in college and need some help on one of my assignments.
I'm using visual basic 2008 express edition.
I'm creating a program that calculates the amount of tip to tip on services rendered based on the bill amount and percentage of the tip. I have the form set up and I'm working on my code.
when I test it everything works fine except my answer is "Tip the taxi driver $300.00"
I need the percentage of tip amount to be recognized as a percentage in the code.
20.00 * 15 = 300 is what I'm getting, I need 20.00 * .015 = 3.00
If you need me to clarify please ask, I will also post my code if needed.
Thanks in advance!
Re: Format variable as percentage?
I understand how to do Format(0.56324, “Percent”)=56.32 % but how will i do that with a variable such as "percentage" ?
Re: Format variable as percentage?
A percentage is equivalent to a decimal number, which is what you need to use for calculations. You can convert to this by dividing by 100:
Code:
cost = 20
percentage = 15
tip = cost * (percentage/100)
formattedTip = Format(tip, “Percent”)
...does that help?
Re: Format variable as percentage?
yes, that works! thanks! I had no idea it was that easy lol.
Another thing that I can seem to get now is my answer.
This is my code for my outcome:
txtTotal.Text = ("Tip the " & (occupation) & (FormatCurrency(total) & "."))
It displays: Tip the taxi driver$3.00.
I can't seem to get a space between the driver and $3.00.
I've tried this:
txtTotal.Text = ("Tip the " & (occupation) & " :" (FormatCurrency(total) & "."))
But I keep getting errors when I run it.
Thanks again
Re: Format variable as percentage?
You're just missing a &:
Code:
txtTotal.Text = ("Tip the " & (occupation) & " " & (FormatCurrency(total) & "."))
Re: Format variable as percentage?