Problems adding float figures together

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

Problems adding float figures together

Post by gotornot »

Hi I am trying to add float figures together but for some reason its not working with the script below any ideas?

$ai = 0;
// Round upp all fees add them together
while ($feeitem = mysql_fetch_array($cartr))
{
$ai2 = $feeitem["fee"];
$ai = $ai + $ai2;
}
echo $ai;

All it does is output the 0

Figures are like 4.65 and 66.50

Any ideas?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Problems adding float figures together

Post by Mark Baker »

Are you sure that your SQL query is actually returning any data?
And what datatype is the fee column?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Problems adding float figures together

Post by Ollie Saunders »

Please use [syntax=php]tags.

If you var_dump($ai2), what value does it hold?[/syntax]
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

Re: Problems adding float figures together

Post by gotornot »

Thanks i have managed to sort it it wasnt holding data but now is
Post Reply