Mutley Posted March 20, 2007 Share Posted March 20, 2007 <?php $value = '100'; $discount_value = '80'; // Value AFTER discount ?> What % do they save? How do I calculate this? Link to comment https://forums.phpfreaks.com/topic/43546-calculating-percentages/ Share on other sites More sharing options...
genericnumber1 Posted March 20, 2007 Share Posted March 20, 2007 basic math? echo ($value - $discount_value) / $value * 100 . '%'; Link to comment https://forums.phpfreaks.com/topic/43546-calculating-percentages/#findComment-211464 Share on other sites More sharing options...
Mutley Posted March 20, 2007 Author Share Posted March 20, 2007 But if the variables are: $value = '100'; $discount_value = '200'; // Value AFTER discount It does a negative percentage, is it possible to say "200%"? Rather than "-100%". Link to comment https://forums.phpfreaks.com/topic/43546-calculating-percentages/#findComment-211645 Share on other sites More sharing options...
DeathStar Posted March 20, 2007 Share Posted March 20, 2007 Hey i made this for my game.. Use it $enperc=(int) ($ir['energy']/$ir['maxenergy']*100); $wiperc=(int) ($ir['will']/$ir['maxwill']*100); $experc=(int) ( $ir['exp']/$ir['exp_needed']*100); $brperc=(int) ($ir['brave']/$ir['maxbrave']*100); $hpperc=(int) ($ir['hp']/$ir['maxhp']*100); $enopp=100-$enperc; $wiopp=100-$wiperc; $exopp=100-$experc; $bropp=100-$brperc; $hpopp=100-$hpperc; print" <b>Energy:</b> {$enperc}%<br /> <img src=bargreen.gif width=$enperc height=10><img src=barred.gif width=$enopp height=10><br /> <b>Will:</b> {$wiperc}%<br /> <img src=/barblue.gif width=$wiperc height=10><img src=barred.gif width=$wiopp height=10><br /> <b>Nerve:</b> {$ir['brave']}/{$ir['maxbrave']}<br /> <img src=barblack.gif width=$brperc height=10><img src=barred.gif width=$bropp height=10><br /> <b>EXP:</b> {$experc}%<br /> <img src=baryellow.gif width=$experc height=10><img src=barred.gif width=$exopp height=10><br /> <b>Health:</b> {$hpperc}%<br /> <img src=barwhite.gif width=$hpperc height=10><img src=barred.gif width=$hpopp height=10>"; Just use it as text .. Link to comment https://forums.phpfreaks.com/topic/43546-calculating-percentages/#findComment-211647 Share on other sites More sharing options...
Barand Posted March 20, 2007 Share Posted March 20, 2007 But if the variables are: $value = '100'; $discount_value = '200'; // Value AFTER discount It does a negative percentage, is it possible to say "200%"? Rather than "-100%". You wanted to show the saving, which is -100% 200% is the discount value as percentage of the value - not the same thing. Link to comment https://forums.phpfreaks.com/topic/43546-calculating-percentages/#findComment-211660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.