php only adding the first digit instead of entire number
I recently moved my website over to Blue Host and this function that's part of a loop:
if ($InvoiceType == '18')
{
echo 'Sum Before addition = ' . $sumInvoice . '<br/>';
$sumInvoice += $complete[$key][5];
print 'Invoice being added = ' . $complete[$key][5] . '<br/>'
. 'Sum after addition = '. $sumInvoice . '<br/>';
}
Is returning this:
Sum Before addition = 0
Invoice being added = 15174.20
Sum after addition = 1
Sum Before addition = 1
Invoice being added = 4604.25
Sum after ad开发者_StackOverflow社区dition = 5
Sum Before addition = 5
Invoice being added = 63810.83
Sum after addition = 11
dump of $complete:
Array
(
[0] => Array
(
[0] => 2161
[1] => 638697
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 15174.20
[6] => 04/01/2011
[7] => 2/1-2/28/11 Fairlawn
[8] => PM2
[9] => 18
)
[1] => Array
(
[0] => 2161
[1] => 638698
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 4604.25
[6] => 04/01/2011
[7] => 2/1-2/28/11 Atrium
[8] => PM2
[9] => 18
)
[2] => Array
(
[0] => 2161
[1] => 638699
[2] => CLIV0286
[3] => Central Medical Supply Inc.
[4] => 0.00
[5] => 63810.83
[6] => 04/01/2011
[7] => 2/1-2/28/11 Parsippany
[8] => PM2
[9] => 18
)
)
What am I doing wrong?
So this does not work?
$sumInvoice = 0;
//Init Loop
if ($InvoiceType == '18')
{
echo 'Sum Before addition = ' . $sumInvoice . '<br/>';
$sumInvoice = 0 + floatval(trim($complete[$key][5])) + floatval($sumInvoice);
print 'Invoice being added = ' . $complete[$key][5] . '<br/>'
. 'Sum after addition = '. $sumInvoice . '<br/>';
}
Try this small scale test:
$val = "10.25";
echo (floatval($val) + 10);
$sumInvoice += (float)$complete[$key][5];
or
$sumInvoice += floatval( $complete[$key][5] );
floatval()
精彩评论