在PHP中将方程式答案设置为两位小数

时间:2016-07-18 03:06:44

标签: php

$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

2 个答案:

答案 0 :(得分:0)

轻松圆()

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

答案 1 :(得分:0)

使用round()

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