所以我有这个代码......
$remaining = $remaining + $row['total'];
这是在一个foreach循环中..
foreach($clientArrayInvoice as $key => $row)
它的作用是遍历每条记录并将总数添加到该$remaining
变量中,一些记录总数是正数,一些是负数,它似乎工作正常,但我需要在$remaining
完成记录后显示变量我把这个作为结果之一......
-2.84217094304E-14
这是从哪里冒出来的,所有的数学加起来应该是0
而不是-2.84217094304E-14
我究竟做错了什么?
这是总数来自的查询
select i.invoiceid as transactionid, i.date, i.total,
i.total - (select ifnull(sum(p.amount), 0) from payment p where p.invoice = i.invoiceid) as remainingbalance,
'invoice' as transaction_type
from invoice i inner join client c
on i.client = c.clientid
where i.isdeleted = 0 and i.client = " . $clientId . "
union
select p.paymentid as transactionid, p.date,(0 - p.amount) as total, p.invoice, 'payment' as transaction_type
from payment p inner join invoice i
on i.invoiceid = p.invoice
inner join paymenttype
on paymenttype.paymenttypeid = p.paymenttypeid
inner join client c
on c.clientid = i.client
where c.clientid = " . $clientId . "
and i.isdeleted = 0
order by date
谢谢,我很感激你的努力。