SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do i make a number always have 2 digits

    Hello all,

    I am currently trying to generate a 7 digit invoice number. The first four are created by the db, then I have a 0 used as a spacer and the last 2 digits are the quantity. eg 1234002. Is there an easy way to add a 0 infront of a single digit quantity.

    Cheers
    AD

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $a sprintf("%02d"$number); 

  3. #3
    SitePoint Evangelist Rodney H.'s Avatar
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another option is using the number_format() function:

    PHP Code:
    <?php
    $a 
    number_format($number2);
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for that. i take it the if you went %04d it would have 4 digits


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
  •