# JavaScript to figure percentage

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
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fixer of ProblemsCommented:
The percentage of 'x' in 'y' is "(x/y)*100".  I don't see where your data is going to get that for you.
Commented:
Independently:

Dependently:

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Software EngineerAuthor Commented:
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.
Software EngineerAuthor Commented:
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(")", ""))
``````

I'm trying to replicate this process on the client side.
Commented:
But I already gave you the code? You never tried it?
Software EngineerAuthor Commented:
My apologies. I wasn't aware you could do

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

in JavaScript. I'll try it today.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.