We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# How to clalculate percent difference between two vlaues

on
Medium Priority
427 Views
Say I have two labels on my page:

Label 1 has a value of 100
Label 2 has a value of 140

How do I calculate the % difference between these 2 values in VB?
Comment
Watch Question

## View Solution Only

Top Expert 2009

Commented:
That should be:

dim percentage As Integer = Abs(val1 / val2 * 100 - 100)

Top Expert 2009
Commented:
To go from a label to a number, use:

Integer.Parse(Label1.Text)

So, the whole code may become:

Dim percentage As Integer = Abs(Integer.Parse(Label1.Text) / Integer.Parse(Label2.Text) * 100 - 100)

Of course, the order matters. From 100 to 140 is a 40% increase, from 140 to 100 is 28.5% decrease. You may remove ABS if you want to know whether it is increase or decrease:

From 140 to 100:

100 / 140 = 0.7143
0.7143 * 100 = 71.43
71.43 - 100 = -28.57

From 100 to 140

140 / 100 = 1.4
1.4 * 100 = 140
140 - 100 = +40

Not the solution you were looking for? Getting a personalized solution is easy.

CERTIFIED EXPERT

Commented:
(100/label1)*(label2-label1)

Will give you the % difference between them in terms of label1%
Top Expert 2009

Commented:
That'd be the same road to heaven, differently formulated ;)
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile