0

如何四舍五入mysql结果值

$earnedbasic=$runrows['salary']/$runrows['days']*$runrows['countdaystotal'];

示例:工资除以天数乘以工作日

150 salary
29 days
30 workingdays

150/29x30=155.17241

如果结果是这样的,那么我现在想要整数值示例 155.17241 并且我只想要 155.173 请帮我解决这个问题

<?php



       while ($runrows = mysql_fetch_assoc($run))
       {

        //get data
       $workerid = $runrows['workerid'];
       $keywords = $runrows['keywords'];
       $salary =  $runrows['salary'];
       $days = $runrows['days'];
       $countdaystotal = $runrows['countdaystotal'];
       $earnedbasic=$runrows['salary']/$runrows['days']*$runrows['countdaystotal'];


 echo "<table class='sortable' border='1' cellpadding='10'>";
        echo "<tr> <th>ID</th> <th>Name</th><th>Basic</th><th>Days</th> <th>Earned Basic</th><th>Total Salary</th></tr>";


     echo "<tr width='50%' onmouseover=\"this.style.backgroundColor='#999999';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\"><td width='20%'><a href=\"detail.php?id=$id\" class=\"style1\">$workerid</a></td>
     <td width='20%'>$keywords</td>
    <td width='20%'>$salary</td>
     <td width='20%'>$countdaystotal</td>
     <td width='20%'>$earnedbasic</td></tr>";


echo "</table>";
       }

     }



    }


?>
4

2 回答 2

2

呃...round($earnedbasic,3)应该这样做。

于 2013-01-29T18:43:38.150 回答
0
<td width='20%'>".round($earnedbasic, 3)."</td>

或者

$earnedbasic=round($runrows['salary']/$runrows['days']*$runrows['countdaystotal'],3);
于 2013-01-29T18:45:58.083 回答