Solved

JavaScript to figure percentage

Posted on 2014-11-06
6
91 Views
Last Modified: 2014-11-29
I have 4 Labels.
Label1 will always have a value of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10 though this value will ultimately represent a percent.

Label2 will always have a whole number value (0-infinity).

Label3 is also always going to be a whole number, and should be a result of the value of label2 times the value of .1, .02, .03, .04, .05, .06, .07, .08, or .09 (and always rounded up when needed. Basically I'm trying to figure out a percentage.

Label4 is just the value of Label3 + the value of Label2

For example:
Label1 = 4
Label2 = 60
Label3 should equal "3" (60 * .04 = 2.4...rounded up is 3)
Label4 should be 63 (Label2 is 60 + Label3 which is 3 = 63)


Any mathletes out there wanna give it a shot?
TIA
0
Comment
Question by:mwmiller78
  • 3
  • 2
6 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40427799
The percentage of 'x' in 'y' is "(x/y)*100".  I don't see where your data is going to get that for you.
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40428105
Independently:
Your answer is for Label3 = Math.ceil((Label1/100)*Label2)
Your answer is for Label4 = Math.ceil((1+(Label1/100))*Label2)

Dependently:
Your answer is for Label3 = Math.ceil((Label1/100)*Label2)
Your answer is for Label4 = Label2 + Label3
0
 

Author Comment

by:mwmiller78
ID: 40428322
Dave, technically the percent is given (Label1) so I suppose the title was slightly misrepresented. In my example Label3 is "3" because the given paramater (Label1) is "4" and the other given paramenter (Label2) is 60. 60 * 4% is 2.40. Since we're rounding up no matter what, the answer (Label3) is "3".

And Label4 is just Label2 + Label3

Sorry for the confusion, that makes sense.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mwmiller78
ID: 40453822
Here's what I'm currently doing on the server side if it helps to make sense.

        If lblPercentOveralge.Text <> "0%" Then
            If lblFinalOrderQuantity.Text <> "0" Then
                Dim strPO As String = ".0" & lblPercentOveralge.Text.Replace("%", "")
                If lblPercentOveralge.Text = "10%" Then
                    strPO = ".1"
                End If
                Dim intPO As Decimal = Convert.ToDecimal(strPO)
                Dim intAQ As Integer = Convert.ToInt32(lblFinalOrderQuantity.Text)
                Dim intOQ As Double = Math.Ceiling(intAQ * intPO)
                lblOverageQty.Text = "(+" & intOQ.ToString & ")"
            Else
                lblOverageQty.Text = "(+0)"
            End If
        Else
            lblOverageQty.Text = "(+0)"
        End If
        lblActualProductionQuantity.Text = Convert.ToInt32(lblFinalOrderQuantity.Text) + Convert.ToInt32(lblOverageQty.Text.Replace("(+", "").Replace(")", ""))

Open in new window


I'm trying to replicate this process on the client side.
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 40454861
But I already gave you the code? You never tried it?
0
 

Author Comment

by:mwmiller78
ID: 40455020
My apologies. I wasn't aware you could do

Label3 = Math.ceil((Label1/100)*Label2)

Open in new window


in JavaScript. I'll try it today.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now