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

私のコードは動作しますが、私は小数点以下2桁まで利益を設定する必要があります。 RM 373037194.867713152の代わりに、私はRM 373037194.87と表示したい。PHPで式アンサーを2小数点に設定

答えて

0

ラウンドで簡単()

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

使用round()

round($row['SUM(profit)'], 2); // round to two decimal places 
関連する問題