Insert leading zeros

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Insert leading zeros

    I have a string of digits that looks like something like these: 0025,
    1234, 0001, 1003, and so on. They are all 4 digits in length. Then
    when I increment one of them by 1, I want to still have 4 digits for the
    value (it should insert the leading zeros if needed). Is there any type
    of function that will force the incremented value to be exactly 4 digits
    no matter what number it increments? Please let me know if there is a
    function that will insert these leading zeros or truncate it to 4 digits
    if necessary. Thanks.

    Matt

    Matt Palermo Guest

  2. Similar Questions and Discussions

    1. Leading Zeros not being read from Excel Query
      We are having an odd problem when trying to read in a query from Excel. What we are trying to do: We have a page where users will upload an Excel...
    2. Disappering leading zeros
      Have a problem that has me swinging. I have a MS Access d/b that contains a zip code directory. Updates are done via a web-based ColdFusion form....
    3. CSV file - Leading Zeros
      Is there a way to write a CSV file so that excel wont drop the leading zero's from fields? I could use spreadsheet::writeexcel or OLE but that's...
    4. missing strip function in DB2 8.1 -- remove leading zeros
      sujit <yhkumars@yahoo.com> wrote: Where did you have the STRIP function? It didn't exist in version 7....
    5. CSV for Excel - Problem with Leading Zeros
      Can we consider change the string to: ' 0000563' ? Luke (This posting is provided "AS IS", with no warranties, and confers no rights.)
  3. #2

    Default Re: [PHP] Insert leading zeros

    Matt Palermo <mpalermo@vt.edu> wrote:
    > I have a string of digits that looks like something like these: 0025,
    > 1234, 0001, 1003, and so on. They are all 4 digits in length. Then
    > when I increment one of them by 1, I want to still have 4 digits for the
    > value (it should insert the leading zeros if needed). Is there any type
    > of function that will force the incremented value to be exactly 4 digits
    > no matter what number it increments? Please let me know if there is a
    > function that will insert these leading zeros or truncate it to 4 digits
    > if necessary. Thanks.
    $var = sprintf("%04d", $var+1);

    Curt
    --

    Curt Zirzow Guest

  4. #3

    Default RE: [PHP] Insert leading zeros

    Thanks a lot. It works like a charm!

    -----Original Message-----
    From: Curt Zirzow [mailto:curt@zirzow.dyndns.org]
    Sent: Tuesday, July 15, 2003 8:45 PM
    To: [email]php-general@lists.php.net[/email]
    Subject: Re: [PHP] Insert leading zeros

    Matt Palermo <mpalermo@vt.edu> wrote:
    > I have a string of digits that looks like something like these: 0025,
    > 1234, 0001, 1003, and so on. They are all 4 digits in length. Then
    > when I increment one of them by 1, I want to still have 4 digits for
    the
    > value (it should insert the leading zeros if needed). Is there any
    type
    > of function that will force the incremented value to be exactly 4
    digits
    > no matter what number it increments? Please let me know if there is a
    > function that will insert these leading zeros or truncate it to 4
    digits
    > if necessary. Thanks.
    $var = sprintf("%04d", $var+1);

    Curt
    --


    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

    Matt Palermo Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139