Convert to decimal number [duplicate]

-1

I have a script that calculates the total of values and then shows the total value in an echo. The problem is that the value is shown without any semicolons, eg: 82700 to: 827.00 I would like to convert it to decimal number but it still is not working.

<?php // Make a MySQL Connection $con = mysql_connect('', 'flash548_passhms', 'passhms');

if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db("flash548_passhms", $con);

$query = "SELECT month, SUM(overhead) FROM projections_sample GROUP BY month";
$result = mysql_query($query) or die(mysql_error());

// Print out result 
while($row = mysql_fetch_array($result)){
    echo "Despesas". $row['month']. " R$". $row['SUM(overhead)']; //overhead
    echo "<br />";
} 

?>
    
asked by anonymous 26.04.2014 / 17:10

1 answer

0

It looks like your data is stored in cents, since they return from the database as INT (based on the problem description). The easiest (assuming the above) is to make the decimal number in the query:

SELECT month, ROUND(SUM(overhead)/100, 2) FROM projections_sample GROUP BY month

This will already give you a decimal for PHP to display.

    
26.04.2014 / 19:06