I have the following piece of code for a very simple PHP polling script
<h2>Result:</h2>
<table>
<tr>
<td>Yes:</td>
<td><img src="poll.gif"
width='<?php echo(100*round($yes/($no+$yes+$maybe),3)); ?>'
height='20'> <?php echo(100*round($yes/($no+$yes+$maybe),3)); ?>% </td>
</tr>
<tr>
<td>No:</td>
<td><img src="poll.gif"
width='<?php echo(100*round($no/($no+$yes+$maybe),3)); ?>'
height='20'> <?php echo(100*round($no/($no+$yes+$maybe),3)); ?>% </td>
</tr>
<tr>
<td>Maybe:</td>
<td><img src="poll.gif"
width='<?php echo(100*round($maybe/($no+$yes+$maybe),3)); ?>'
height='20'> <?php echo(100*round($maybe/($no+$yes+$maybe),3)); ?>% </td>
</tr>
<tr>
</table>
However, if they all have an equal amount of votes, i get a result like 33.333333333%. How do i reduce this to only one decimal place?
Thanks in advance!
by using round after you have multiplied by 100, not before.
Your code could also be simplified a little, to something like this