Jump to content

Percentage of 2 Numbers


Recommended Posts

I have a GUI setup like this

Won: 0

Lost: 0

Total: 0

Rate: 100%

 

and a add and subtract button, if I were to push add 5 times and lost 10 times it would look like this

Won: 5

Lost: 10

Total: 15

Rate: 50%

 

Sample of my codes add/subtract buttons

Case $Add
$Wonz = StringTrimLeft(GUICtrlRead($Won), 5)
$Subz = StringTrimLeft(GUICtrlRead($Lost), 6)
$Totz = StringTrimLeft(GUICtrlRead($Total), 7)
GUICtrlSetData($Won, "Won: " & $Wonz +1)
GUICtrlSetData($Total, "Total: " & $Totz +1)
 
If Not GUICtrlRead($Wonz) = 0 And Not GUICtrlRead($Subz) = 0 Then
If $Wonz > $Subz Then
GUICtrlSetData($Rate, "Rate: " & Round($Subz / $Wonz) * 100, 2)
Else
GUICtrlSetData($Rate, "Rate: " & Round($Wonz / $Subz) * 100, 2)
EndIf
EndIf
Case $Sub
$Wonz = StringTrimLeft(GUICtrlRead($Won), 5)
$Subz = StringTrimLeft(GUICtrlRead($Lost), 6)
$Totz = StringTrimLeft(GUICtrlRead($Total), 7)
GUICtrlSetData($Lost, "Lost: " & $Subz +1)
GUICtrlSetData($Total, "Total: " & $Totz +1)
 
If Not GUICtrlRead($Wonz) = 0 And Not GUICtrlRead($Subz) = 0 Then
If $Wonz > $Subz Then
GUICtrlSetData($Rate, "Rate: " & Round($Subz / $Wonz) * 100, 2)
Else
GUICtrlSetData($Rate, "Rate: " & Round($Wonz / $Subz) * 100, 2)
EndIf
EndIf

This doesn't work though and I cannot wrap my ahead around what im doing wrong

 

[edited]

really just need help with this part

 

If $Wonz > $Subz Then
GUICtrlSetData($Rate, "Rate: " & $Subz / $Wonz * 100)
Else
GUICtrlSetData($Rate, "Rate: " & $Wonz / $Subz * 100)
EndIf
 
it seems like it should work
Edited by SkellySoul
Link to comment
Share on other sites

The rate is the ratio of wins vs lost and total is just the wins and loses added together.

I'm just trying to get the percentage of two numbers but it gives me funny results at times.

Edited by SkellySoul
Link to comment
Share on other sites

I was trying to do "(win/lost) * 100" but realized that if they're 0 that won't work because you cannot divide by 0. So I threw in a piece of code that won't return the rate if either of them are at 0. I also know that you have to divide with the lower number first to get the actual percentage and I did that by using a greater than operator ">".

For some reason though the code isn't written properly because it doesn't return the proper values.

 

[Edit]

$Value_Low = 5
$Value_High = 15
 
$Value = ($Value_Low / $Value_High) * 100
 
MsgBox(0 , "", Round($Value, 2))

This is working, ill have to go over my code and find the problem.

 

Appreciate your help!

Edited by SkellySoul
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...