How do I automatically add commas to numbers?

Discussion in 'PHP' started by peppy, Jun 16, 2010.

  1. #1
    Greetings,

    I have numbers stored in my MySQL database that look like this:
    5234552346234

    How can I get PHP to display that number as this?:
    5,234,552,346,234

    Thanks
     
    peppy, Jun 16, 2010 IP
  2. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Use number_format().

    Example:

    <?php
      $num = "9001";
      echo number_format($num);    // displays: 9,001
    ?>
    
    PHP:
    The fourth parameter specifies the separator. The default, of course, is a comma.
     
    Cozmic, Jun 16, 2010 IP
  3. peppy

    peppy Active Member

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Excellent, this is exactly what I'm looking for!

    Thanks!
     
    peppy, Jun 17, 2010 IP