Avatar of JessyRobinson1234
JessyRobinson1234
 asked on

FomatPercent

I have the following vb statement:

Dim percentage As Integer = (Me.lblAGR.Text / Me.lblBGR.Text * 100 - 100) --> returns 62

How can I return 62% and keep percentage as integer?
Other option would be to store as string and when I update the value replace % with '' and convert back to integer

I tried FormatPercent

ASP.NET

Avatar of undefined
Last Comment
abel

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Robitaille

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
abel

There must be a location where you want to show the percentage. Depending on what you are using, you can use the format specifiers there (i.e., on a label) to show the percent. An integer is only the number and will not contain anything else then digits.
abel

Note that using the percentage in the format specifier expects a value between 0 an 1 (in other words, it will multiply with 100). So, you can do the following:

lblPercent.Text = (percentage / 100).ToString("0%")

On your webpage, you need the following:

<asp:Label runat="server" ID="lblPercent" />
JessyRobinson1234

ASKER
davrob60,
Tried that and it's a step in the right direction, the result is: 62.978963464422%. How can I do rounding and not display decimals (63%)
Thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
abel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Robitaille


String.format("{0:f0}%", percentage)  
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx 
abel

Alternatively, you can consider this:

lblPercent.Text = percentage & "%"

easier is hardly possible, sometimes we do not need complex formatters to get our task done ;)
JessyRobinson1234

ASKER
Let me ask you this to determine best practice: what would be the best way for the database: store the value as nvarchar(5), double or int?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
David Robitaille

that depend of multiple factor, but in my opinion, double.
abel

I second the opinion of davrob60. When you store something for later retrieval, best practice is to keep as much information with it as possible. With the choice you gave, the most details are stored with the double.

You may consider storing the two individual values, which would leave the calculation result out of the database. In terms of sound design, that is often better. You can still have that column with the calculation in it, but then make it a computed column. That is, imo, an even better "best practice" because it leaves all options open for the future.