Dethman Posted July 12, 2008 Share Posted July 12, 2008 Hello all, I am trying to figure out how to get the percentage between two numbers such as "2500" and "1250" I am using this code for the SQL query but cant figure out how to get a percentage range between 1% and 100% the percentage is the percent of the damaged weapon. its like this, if weapon is 25% damaged I need to it to say Weapon Status 75% of capable power lol does anyone get this? mysql_query("select `weaponDefaultStrength` AND `strength` from `user_weapons` where `userid`='$userID'") or die(mysql_error()); Please Help ??? Link to comment https://forums.phpfreaks.com/topic/114415-need-help-fast-getting-a-percentage-between-two-numbers/ Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Well if 1250 is your weapons current status and 2500 is your weapons max status or health or whatever. Then apply the maths rule: PERCENT = (1250/2500) * 100 So... Put this in your game: $weaponFullStrength = 1800; $weaponStrength = 900; $damangePercent = (ceil($weaponFullStrength / $weaponStrength) * 100); //this gives us the damage percentage $capablePower = 100 - $damagePercent; echo "Weapon Status: {$capablePower}% of capable power."; Hope that cleared a few things up, and I answered your question. (Is it ceil() in PHP, I'm sure it is. Darn javascript!) Link to comment https://forums.phpfreaks.com/topic/114415-need-help-fast-getting-a-percentage-between-two-numbers/#findComment-588373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.