kevinfwb Posted January 25, 2007 Share Posted January 25, 2007 Hello - I have a PHP script that outputs the values from a MySQL database. The code works as needed aside from the numeric formatting. For example, the value of a field is 1234.567 (I used 3 digits because of how it is calculated and compounded)I would like to format the output to be $1,234.57I've tried using both the number_format money_format, however, I can not get the syntax right. I usually get an error or the actual output shows the code depending on the syntax I'm using.Here is a code snippet that I am working with. echo " <tr>\n";echo " <td><div align=\"left\"></div></td>\n";echo " <td><div align=\"center\">{$row['ar18']}</div></td>\n";echo " <td> </td>\n";echo " </tr>\n";Thank you for your time - Kevin Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 try number format()? Quote Link to comment Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 Sorry, I should have clarified a bit. It's not that I can't get the syntax of formatting it correctly.If I just echo number_format($variable,2); I get the right formatting.What I am having trouble with is the combination of number_format and the HTML in the same echo statement. echo " <td><div align=\"center\">format_number( {$row['ar18']} ,2) </div></td>\n";Throws an error as well as all variations that I've tried so far.Did that make any sense? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 What have you tried?Ken Quote Link to comment Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 I edited my last post if you haven't re-read it. I've also triedecho " <td><div align=\"center\">",number_format(,"{$row['mr20']}",,2)"</div></td>\n";and some other variations.. all throwing an error. I'm realtively new to PHP/MySQL most of everything I've done so far is by using a piece by piece trial and error method. This is just stumping me. As I said I can get it to work with a standard echo, just not within the html table. Quote Link to comment Share on other sites More sharing options...
corbin Posted January 25, 2007 Share Posted January 25, 2007 echo "<td><div align=\"center\">" . number_format(,"{$row['mr20']}",,2) . "</div></td>\n";Should work :p Quote Link to comment Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 Parse error: syntax error, unexpected ',', expecting ')' in ...... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 You don't need the "{ }" inside the function:[code]<?phpecho '<td><div align="center">' . number_format($row['mr20'],2) . "</div></td>\n";?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
kevinfwb Posted January 25, 2007 Author Share Posted January 25, 2007 That was it, I really appreciate your help.-Kevin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.