$yes = '18'; $no = '36';
how do i get the percentage of Yes and the percent of No based on both variables combined?
$sum=$yes+$no; if ($yes>$no) { $yespc=ceil($sum/$yes); #majority rules!! $nopc=floor($sum/$no); } elseif ($no>$yes) { $yespc=floor($sum/$yes); $nopc=ceil($sum/$no); } else { $yespc=$nopc=50; }
Kludge alert! 😃
Wait for the heavyweights!!
<?php $yes = 18; $no = 36; $total = $yes+$no; $pY = $yes/$total; echo $pY; echo "<br>"; echo $pY*100; echo "%"; ?>
We both forgot something --- try this instead...
<? $yes=36; $no=18; $sum=$yes+$no; $yespc=number_format((($yes/$sum)*100),2); $nopc=number_format((($no/$sum)*100),2); echo $yespc."%---Yes<br><br>"; echo $nopc. "%---No"; ?>
😉
yea.. good job Dalecosp 🙂
now we're talking 😃
thanx guys.