I want to calculate the percentage between two numbers.
Before asking here, I looked at other pages and questions such as:
- https://www.codevscolor.com/python-find-change-percentage-two-numbers
- How to check change between two values (in percent)?
- Calculating change in percentage between two numbers (Python)
None of the pages above helped me.
The problem:
I have, two numbers: 3
upvotes and 2
downvotes, and I want to calculate the percentage of how many people upvoted the message in relation to the downvotes.
My desired outcome is that the higher the upvotes get, the higher the calculated percentage gets.
Example:
3
upvotes and 3
downvotes: 50% upvotes
4
upvotes and 3
downvotes: XX% upvotes (Higher than 50%
)
Here is what I have tried to do:
percentage = (data[str(payload.message_id)]['downvote'] / data[str(payload.message_id)]['upvote']) * 100
# The higher it gets, the lower the number gets -> 10 to 6 = 60%
((data[str(payload.message_id)]['downvote'] / data[str(payload.message_id)]['upvote']) * 100) / 2
# Also calculates things wrong -> 16 to 6 = 37.5%
float(data[str(payload.message_id)]['upvote'])-data[str(payload.message_id)]['downvote'])/data[str(payload.message_id)]['downvote'])*100
Maybe this is just a simple mistake I made, but I am not seeing it.
data[str(payload.message_id)]['upvote']
and data[str(payload.message_id)]['downvote']
are obviously the numbers I saved somewhere.