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

Link to comment
Share on other sites

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!)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.