我从 XMl 中获得了一些奖励,并想计算总和。为什么不是$M_commission
166.63 的输出?
$i = 0;
$commission_trans = 0;
foreach($responseXml->lead as $lead)
{
if ($i == 0) {
$last_trans = $lead->leadTime;
}
$commission_trans = $commission_trans + $lead->reward;
echo $lead->reward;
echo "\n";
$i++;
}
$M_lastclick = $last_trans;
$M_commission = number_format($commission_trans, 2);
echo $M_commission;
echo "\n";
echo $M_lastclick;
输出:100.0 0.63 3.0 30.0 3.0 30.0 166.00 2013-05-10T13:42:01.058+02:00
我试过了
$commission_trans = number_format($commission_trans + $lead->reward, 2);
但相同的输出。
很多!