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?


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.

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.