[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Calculating percentage...

Posted on 2007-04-01
6
Medium Priority
?
1,941 Views
Last Modified: 2008-01-09
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
Comment
Question by:convertix
6 Comments
 
LVL 67

Assisted Solution

by:sirbounty
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

by:convertix
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

by:convertix
ID: 18834335
I meant to say, when I take 2 and divide it by 5.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

Assisted Solution

by:Mike Tomlinson
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

by:
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

Industry Leaders: 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!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Screencast - Getting to Know the Pipeline
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 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