otuatail Posted January 21, 2010 Share Posted January 21, 2010 Hi I have adb field `Cost` decimal(4,2) NOT NULL default '0.00' I want to iterate through the table put data into a <table> What i have is this but it dosn't work. $totals = (float)"0.00"; while ($row = mysql_fetch_array($rs)) { $totals .= (float)$row["Cost"]; } echo (float)$totals; Can't figure this addition. Thanks Link to comment https://forums.phpfreaks.com/topic/189326-php-maths-problem/ Share on other sites More sharing options...
Mchl Posted January 21, 2010 Share Posted January 21, 2010 .= is for concatenating strings. To add numbers use += Link to comment https://forums.phpfreaks.com/topic/189326-php-maths-problem/#findComment-999436 Share on other sites More sharing options...
otuatail Posted January 21, 2010 Author Share Posted January 21, 2010 Ok thanks. the only problem I have is i get 6163 nit 6163 .00 if this is a float, I need .00 Desmond. Link to comment https://forums.phpfreaks.com/topic/189326-php-maths-problem/#findComment-999444 Share on other sites More sharing options...
Mchl Posted January 21, 2010 Share Posted January 21, 2010 number_format or money_format Link to comment https://forums.phpfreaks.com/topic/189326-php-maths-problem/#findComment-999445 Share on other sites More sharing options...
otuatail Posted January 22, 2010 Author Share Posted January 22, 2010 Thanks for your help problem solved. Link to comment https://forums.phpfreaks.com/topic/189326-php-maths-problem/#findComment-999708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.