Jump to content

Division by Zero help


LastFather

Recommended Posts

Hello,

 

On my Stats page on my MMOG text based mafia game, i get a Division by zero error on the My Stats page. I can't work out what it is. Here is the bit of code it relates to (The bottom line - percentage)

 

$currank=$fetch->rank;

 

$rankp = $fetch->rankpoints;

 

 

 

if ($currank == "Empty-suit"){

 

$max = "100";

 

$old="0";

 

}elseif ($currank == "Delivery Boy"){

 

$max = '300';

 

$old="100";

 

}elseif ($currank == "Picciotto"){

 

$max = '800';

 

$old="300";

 

}elseif ($currank == "Shoplifter"){

 

$max = '1500';

 

$old="800";

 

}elseif ($currank == "Pickpocket"){

 

$max = '3500';

 

$old="1500";

 

}elseif ($currank == "Thief"){

 

$max = '6000';

 

$old="3500";

 

}elseif ($currank == "Associate"){

 

$max = '8000';

 

$old="6000";

 

}elseif ($currank == "Mobster"){

 

$max = '12000';

 

$old="8000";

 

}

elseif ($currank == "Soldier"){

 

$max = '15000';

 

$old="12000";

 

}

elseif ($currank == "Swindler"){

 

$max = '18000';

 

$old="15000";

 

}

elseif ($currank == "Assassin"){

 

$max = '22000';

 

$old="18000";

 

}

elseif ($currank == "Local Chief"){

 

$max = '28000';

 

$old="22000";

 

}

elseif ($currank == "Chief"){

 

$max = '34000';

 

$old="28000";

 

}

elseif ($currank == "Bruglione"){

 

$max = '40000';

 

$old="34000";

 

}

elseif ($currank == "Godfather"){

 

$max = '200000';

}

$percent = round((($rankp-$old)/($max-$old))*100, 2);

?>

Link to comment
https://forums.phpfreaks.com/topic/206390-division-by-zero-help/
Share on other sites

I've found that a good way to troubleshoot such a problem is by printing the script you are trying to run.

 

what I mean is using this line

<?php
$percent = round((($rankp-$old)/($max-$old))*100, 2);
?>

 

and printing what its actually doing

<?php
echo "$percent = round((($rankp-$old)/($max-$old))*100, 2);";
?> 

I've found that a good way to troubleshoot such a problem is by printing the script you are trying to run.

 

what I mean is using this line

<?php
$percent = round((($rankp-$old)/($max-$old))*100, 2);
?>

 

and printing what its actually doing

<?php
echo "$percent = round((($rankp-$old)/($max-$old))*100, 2);";
?> 

 

I got this - = round(((10213-)/(-))*100, 2);

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.