Sign in to follow this  
Followers 0
SkellySoul

Percentage of 2 Numbers

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Not realy sure what you are trying to do here.. what is your "Rate"? If its percentage won you have the math all wrong..

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

If you want the %win you do like this

(win/total) * 100

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

I managed to fix it. I think earlier today I was over thinking the task and made it way more complicated then needed.

Thanks again :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0