Percent problem.
BlitzMax Forums/BlitzMax Beginners Area/Percent problem.
| ||
Hey everyone! I have a quick question about how to calculate percents. I have two variables in my game, one which keeps track of how many times you attack, and the other which keeps track of how many times you hit with your attack. What I want to do, is figure out what percent of the attacks hit. I.e, lets say you fire off 233 attacks and hit with 154. What percent of 233 is 154? If someone could answer this, that would be great ;) |
| ||
Clues in the question - you hit 154/233 times.pc = (float(hits)/attacks) * 100 Remember that either hits OR attacks needs to be converted to a float, otherwise you'll always get 0 as the result if both sides are integer. |
| ||
Ok! Thanks Gfk, much appreciated :) |