如何在echo中插入循环代码?

时间:2018-02-09 01:49:44

标签: php html decimal

我希望数字有2位小数,因为它显示了所有十进制数。这是我的代码:

<?php 
    $add=mysqli_query($conn,'SELECT SUM(fil), SUM(math), SUM(aralp), 
    SUM(mapeh), SUM(esp), SUM(mtb), (SUM(total)/5), SUM(mps) from `grade1`');

    while($row1=mysqli_fetch_array($add))
    {
        $mark=$row1['SUM(fil)'];
        $mark3=$row1['SUM(math)'];
        $mark4=$row1['SUM(aralp)'];
        $mark5=$row1['SUM(esp)'];
        $mark6=$row1['SUM(mapeh)'];
        $mark7=$row1['SUM(mtb)'];
        $mark9=$row1['(SUM(total)/5)'];
        $mark10=$row1['SUM(mps)'];
    }
?>

如何在此处插入round(2)

<?php
    echo "<th></th><th>AVERAGE</th>";
    echo "<th>$mark</th>";
    echo "<th>$mark3</th>";
    echo "<th>$mark4</th>";
    echo "<th>$mark5</th>";
    echo "<th>$mark6</th>";
    echo "<th>$mark7</th>";
    echo "<th>$mark9</th>";
    echo "<th>$mark10</th>";
?>

提前谢谢!

1 个答案:

答案 0 :(得分:-1)

这实际上是

echo "<th>".round($mark, 2)."</th>";

现在,我不得不面对另一个问题。