[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Calculating percentage...

Posted on 2007-04-01
Medium Priority
1,940 Views
I need help calculating the percentage of two numbers.  I have two Labels with the values and need to calculate the percentage.

RealPercentage = CDec(Me.lblActualMilestoneHours.Text) \ CDec(Me.lblApprovedMilestone.Text)

The value of lblActualMilestoneHours is 5
The value of lblApprovedMilestone is 2

0
Question by:convertix
[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

LVL 67

Assisted Solution

sirbounty earned 600 total points
ID: 18834274
Hello convertix,
Where are you getting hung up?
What are the meanings of those labels?
I'd suppose either you're getting an error, or you're getting incorrect data.
Have you tried flipping the values?
RealPercentage = CDec(Me.lblApprovedMilestone.Text) / CDec(Me.lblActualMilestoneHours.Text)

Or is it the you were using the backslash, rather than the forward slash?

~sirbounty
0

Author Comment

ID: 18834332
The lblApprovedMilestone is the total amount of hours and the lblActualMilestoneHours is the current number of hours in the current project.  This program is for keeping track of how many hours a developer is taking to complete a project.  The total approved hours is 5 for this milestone and the actual current hours on the project is 2 so I want to figure out the percentage done.  When I use my calculator I get the percentage 40%.  When I take the 5 and divide it by two in VB.NET I get 2 and I can't remember or figure out how to get the proper percentage.
0

Author Comment

ID: 18834335
I meant to say, when I take 2 and divide it by 5.
0

Author Comment

ID: 18834336
And also meant to say....I get 0 (instead of 2)
0

LVL 86

Assisted Solution

Mike Tomlinson earned 600 total points
ID: 18834439
Look CLOSELY at the SLASHES in use.

Your code is using a Backslash "\" which means INTEGER Division will be peformed:
http://msdn2.microsoft.com/en-us/library/0e16fywh.aspx

sirbounty has corrected the problem by replacing it with a Forward Slash "/" which performs regular division.

So keep the variables in the order you have them but use the correct Operator:

RealPercentage = CDec(Me.lblActualMilestoneHours.Text) / CDec(Me.lblApprovedMilestone.Text)
0

LVL 3

Accepted Solution

r1937 earned 800 total points
ID: 18835349
ok ok math problem....

>>>>The lblApprovedMilestone is the total amount of hours and the lblActualMilestoneHours is the current number of hours in the current project.  This program is for keeping track of how many hours a developer is taking to complete a project.  The total approved hours is 5 for this milestone and the actual current hours on the project is 2 so I want to figure out the percentage done
<<<<<

Dim RealPercentage As Decimal
RealPercentage = CDec(Me.lblActualMilestoneHours.Text) / CDec(Me.lblApprovedMilestone.Text) * 100

r1937
0

## Featured Post

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB â€¦
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fiâ€¦