2016-07-18 2 views
0
$query=mysql_query($sql,$connect); 

while($row = mysql_fetch_array($result3)){ 
    echo "Total Profit = RM ". $row['SUM(profit)']; 
    echo "<br />"; 
} 
echo"</br>"; 
echo "<b><u>Total Profit earned </u></b>" ; 
echo"</br>"; 
$query1 = "SELECT country, SUM(profit) FROM `table 1` GROUP BY country"; 
$result1 = mysql_query($query1) or die(mysql_error()); 

while($row = mysql_fetch_array($result1)){ 
    echo "". $row['country']. " = RM ". $row['SUM(profit)']; 
    echo "<br />"; 
} 

내 코드는 작동하지만 소수점 이하 두 자리로 설정해야합니다. RM 373037194.867713152 대신 RM 373037194.87으로 표시하고 싶습니다. 라운드방정식 anser를 PHP에서 두 자리 십진수로 설정하십시오.

답변

0

쉬운()

echo "". $row['country']. " = RM ". round($row['SUM(profit)'], 2); 
0

사용 round()

round($row['SUM(profit)'], 2); // round to two decimal places