Jump to content

[NEED HELP FAST] Getting a Percentage Between Two Numbers...


Dethman

Recommended Posts

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  ???

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. :P Darn javascript!)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.