Here's the code: (file called math_helper.php)
Code: Select all
if ( ! function_exists('percentage'))
{
function percentage($min, $max)
{
$count1 = $min / $max;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
return $count;
}
}Usage example:
Code: Select all
include 'math_helper.php'
$maxhp = '15';
$current_hp = '10';
echo '<div style="width: 110px;background-color:red;">';
echo '<div style="width:'.percentage($current_hp, $maxhp).'%; background-color: green">';
echo $current_hp.'/'.$maxhp.'</div></div>';