- Home /
Simple math?
Hey Guys and Gals!
I am trying something very simple but not yielding the results I desire.
All I want at the moment is the percentage of some hp, this is what I thought would work.
perc = (hp/maxHp)*100;
but apparently not, it starts at 100, but as soon as hp drops, it plummets to 0.
Am I being really dumb?
Thanks
Answer by Eric5h5 · Dec 31, 2013 at 09:37 PM
You need to use floats if you want to do floating point math, otherwise you get integer math. So either hp or maxHp needs to be cast to a float for the purposes of the calculation.
Thanks mate, was driving me nutty. I knew I had the equation right!
Answer by YoungDeveloper · Dec 31, 2013 at 09:25 PM
Am a bit confused, isn't it just:
perc = hp/100; //?
If hp is float, but you want perc as int, you can parse to int using special method.
afraid not old boy. If my starting hp with 350 for example, it would simply return 35.
Your answer
Follow this Question
Related Questions
Mask a HP Bar 0 Answers
Health bar by percentage? (not drawing a box) 4 Answers
players chance of winning is increased based on their level. 0 Answers
Health Bar Lerp 1 Answer
add a percentage to a variable 3 Answers