Jump to content

[SOLVED] Quick PHP - Convert to percentages?


djfox

Recommended Posts

I have the following codes:

<?php
$total = $rows[8] + $rows[9] + $rows[10] + $rows[11] + $rows[12] ;
$per1 = $rows[8]/$total ;
$per2 = $rows[9]/$total ;
$per3 = $rows[10]/$total ;
$per4 = $rows[11]/$total ;
$per5 = $rows[12]/$total ;

if (isset($_GET['results']) && $_GET['results'] == "view") {
echo "<b>Results:</b>";
echo "<br>$rows[3] <b>$rows[8]</b><br><font size=2>$per1 %</font>";
echo "<br>$rows[4] <b>$rows[9]</b><br><font size=2>$per2 %</font>";
echo "<br>$rows[5] <b>$rows[10]</b><br><font size=2>$per3 %</font>";
echo "<br>$rows[6] <b>$rows[11]</b><br><font size=2>$per4 %</font>";
echo "<br>$rows[7] <b>$rows[12]</b><br><font size=2>$per5 %</font>";
echo "<p>$total Votes";
}
?>

 

How can I convert the $per values to display as percentages? Currently they display as 0.5 and so on.

Link to comment
https://forums.phpfreaks.com/topic/70067-solved-quick-php-convert-to-percentages/
Share on other sites

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.