Help w/php decimals

Hello, would someone look at my code and advise how to change. The amt
payable minus the amt paid drops the cents above “.00”. Below is example
of the problem and below that the pertinent code.

                             date 	     days 	  amt

recur? acct# creditor purpose due paid late payable paid due
Y 8538 Purina dog food 2013-01-13 0000-00-00 0 72.99 0.00 72.00

$totdue = $totdue + $row['amtdue'];
$totpaid = $totpaid + $row['paidamt'];
$totowed = $totdue - $totpaid;
$amtdue = str_replace(',', '.', $row['amtdue']);
$paidamt = str_replace(',', '.', $row['paidamt']);
$due = $row['amtdue'] - $row['paidamt'];
$due = str_replace('.', ',', $due);

if ($late > 120)
{ $row['dayslate'] = "pastdue"; }

 // $row['duedate'] = preg_replace('/^[0:-]*$/', '', $row['duedate']);
// $row['datepaid'] = preg_replace('/^[0:-]*$/', '', $row['datepaid']);
// if(str_replace(array('0','-',':'),' ',$row['dayslate'])=>'120');{$row['dayslate']='past due';}
echo "<tr>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['acctno'] . "</td>";
echo "<td>" . $row['bname'] . "</td>";
echo "<td>" . $row['purpose'] . "</td>";
echo "<td>" . $row['duedate'] . "</td>";
echo "<td>" . $row['datepaid'] . "</td>";
echo "<td align=right>" . $row['dayslate'] . "</td>";
echo "<td align=right>" . $row['amtdue'] . "</td>";
echo "<td align=right>" . $row['paidamt'] . "</td>";
echo '<td>', number_format($due, 2, '.', ''), '</td>';
   }
 echo "<tr>";
echo "<td>Gtotals</td>";
echo "<td colspan=6></td>";
echo "<td align=right>" . sprintf("%.2f",$totdue) .
"</td>";
echo "<td align=right>" . sprintf("%.2f",$totpaid) .
"</td>";
echo "<td align=right>" . sprintf("%.2f",$totowed) .
"</td>";
echo "</tr>";
echo "</table>";
mysql_close();
?> 

</body></html>

I believe you want to do this.

 
// Get rid of the thousand separator.	 
$totdue  = str_replace(',', '', $totdue);									
$totpaid = str_replace(',', '', $totpaid); 
$amtdue  = str_replace(',', '', $row['amtdue']);									
$paidamt = str_replace(',', '', $row['paidamt']);
// Do accumlitives 
$totdue  = bcadd($totdue, $amtdue, 2); 
$totpaid = bcadd($totpaid, $paidamt, 2); 
// Subtract Paid from Due
$due = bcsub($totdue, $totpaid, 2);

Just the ticket, thanks

Always get rid of comma’s before doing math. Glad it worked for you.