How do I automatically add commas to numbers?

Discussion in 'MySQL' 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. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    mwasif, Jun 17, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Number format will only work for the thousands separator.
     
    jestep, Jun 17, 2010 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    PHP manual says
    If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.
    The following code gives the exact output that peppy is looking for.
    echo number_format('5234552346234');
    PHP:
     
    mwasif, Jun 19, 2010 IP
  5. phpmatt

    phpmatt Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I was going to suggest the php forum but it looks like you have the answer above
     
    phpmatt, Jun 22, 2010 IP