Getting a percentage between two variables

So I've got three variables. One is PlayerHP, another is PlayerMaxHP and the last one is HPPercentage. I want to get a percentage between PlayerHP and PlayerMaxHP and store it into HPPercentage.

- When initialized PlayerHP = 100 and PlayerMaxHP = 100.

- I take PlayerHP and store it into HPPercentage

- I then take HPPercentage and divide it by PlayerMaxHP

- then I muiltiply HPPercentage by 100 and I should get the result.

At first when both PlayerHP and PlayerMaxHP are the same being 100 it works perfectly fine. I get a percentage output of 100. But the second PlayerHP drops below the 100 then something goes wrong and I get a Percentage output of 0. If PlayerHP is above PlayerMaxHP I get an output of 100 when it should be higher than 100. What is going on here?
So I've got three variables. One is PlayerHP, another is PlayerMaxHP and the last one is HPPercentage. I want to get a percentage between PlayerHP and PlayerMaxHP and store it into HPPercentage.

- When initialized PlayerHP = 100 and PlayerMaxHP = 100.

- I take PlayerHP and store it into HPPercentage

- I then take HPPercentage and divide it by PlayerMaxHP

- then I muiltiply HPPercentage by 100 and I should get the result.

At first when both PlayerHP and PlayerMaxHP are the same being 100 it works perfectly fine. I get a percentage output of 100. But the second PlayerHP drops below the 100 then something goes wrong and I get a Percentage output of 0. If PlayerHP is above PlayerMaxHP I get an output of 100 when it should be higher than 100. What is going on here?

Seeing how I've been doing alot of calculations with variables lately, and succeeding at such, I would most likely beable to help you, but I really need to see the actual event(s) that you have handling this.
It drops to 0/100 because you divide by maxhp first. As it is an integer division, the remainder is dropped. Try multiplying it by 100 first.
It drops to 0/100 because you divide by maxhp first. As it is an integer division, the remainder is dropped. Try multiplying it by 100 first.
Oh would look at that. This worked. Thanks!
Yes, you need to multiply first - that's the whole trick for a lot of integer operations...


This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/getting-a-percentage-between-two-variables.24484/