SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: How to display currency with commas

  1. #1
    SitePoint Zealot Rio's Avatar
    Join Date
    Nov 2001
    Location
    United Kingdom
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to display currency with commas

    Hello all,

    I have a question about how to display currency with commas.

    One of the columns is in type"decimal" at the moment. For example, £12,345,678.00 is inserted (only the number bit, without £ sign) as 12345678.00 in to the database and therefore the output is £ 12345678.00.

    Can I re-format the output in PHP so that the final output on the Web page will be £ 12,345,678.00?

    I think I have to stick to "decimal" type as I have to caluculate the sume of the column.

    Rio

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    number_format() gives you a few options

    www.php.net/number_format

    <?
    $num=12345678.00;
    echo number_format($num,2,'.',',');
    ?>

    - just read the last bit of your post you will need to keep a copy of your $num as number_format() converts it into a string.
    Last edited by firepages; Nov 15, 2001 at 12:59.

  3. #3
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/localeconv

    Hope this helps


    Edit: ah yes, number_format() is nice
    Last edited by Michel V; Nov 15, 2001 at 13:01.

  4. #4
    SitePoint Zealot Rio's Avatar
    Join Date
    Nov 2001
    Location
    United Kingdom
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool! I tried number_format() and it works just fine.

    Thanks for your help, guys.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •