Convert to decimal number

Asked

Viewed 339 times

-1

I have a script that calculates the total values and then demonstrates the total value in an echo. The problem is that the value is demonstrated without colons or commas, ex: 82700 to: 827.00 would like to convert it to decimal number but is not working yet.

<?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 />";
} 

?>
  • 3

    What do you want is the same as this question? http://answall.com/questions/11301/formatteca-de-numeros-php

  • @mustache is basically this.

  • Two tips: 1) SELECT month, SUM(overhead) AS total FROM so you can use $row['total']. 2) $row['total']/100 returns what you want (however, without formatting). To format, I recommend seeing the answer given by @bigown

1 answer

0

It seems that your data is stored in cents, since they return from the bank as INT (based on the description of the problem). 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 give you a decimal for PHP to display.

  • thanks for the relevant information I will test.

  • Hello, I tried the mode reported but nothing appears for viewing, and also no error is reported:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.