Jump to content

money_format inside an HTML table


kevinfwb

Recommended Posts

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.57

I'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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

I edited my last post if you haven't re-read it.  I've also tried

echo "    <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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.