How to display integer data as currency USD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jej1216
    New Member
    • Aug 2006
    • 40

    How to display integer data as currency USD

    Using MySQL to store data that is in integer form. Need to display data as USD (such as $678,321 for the integer value 678321).

    Do I use PHP to do this or straight HTML? I have an HTML Form right now to display the data as it is formatted in MySQL.

    TIA,

    jej1216
  • kenno69
    New Member
    • Jun 2007
    • 9

    #2
    maybe try
    [PHP]echo "$", $your variable to get the integer;[/PHP]
    that will echo $678321
    or if there is loads of numbers you want it doing to
    [PHP]while($row = mysql_fetch_arr ay($result))
    {
    echo "$" .$row['thesqltable'].
    }

    [/PHP]

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      number_format()

      [code=php]echo '$' . number_format($ price, 2, '.', ',');[/code]

      There is also money_format(), but it doesn't work on all servers (Windows in particular).

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        MySQL also has its own FORMAT() function.

        Comment

        • jej1216
          New Member
          • Aug 2006
          • 40

          #5
          Thanks, all.

          In general, is it better practice to do the formatting in PHP or in MySQL?

          Or does it make any difference?

          It's a small table, so I'm not too concerned with execution time.

          - jej1216

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            MySQL should have the raw numbers.

            Comment

            • jej1216
              New Member
              • Aug 2006
              • 40

              #7
              Thanks - I stored the raw numbers in MySQL and used the formatting code for PHP, as suggested. Works like a charm.

              Thanks again,

              jej1216

              Comment

              Working...