Results 1 to 4 of 4

Thread: how to add 0's to a number

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    how to add 0's to a number

    I want to add 0s to a number.

    Let's say I have 5, I have to add 4 digits like this:
    00005

    If I have 17 I have to add 3 digits like this:
    00017
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: how to add 0's to a number

    str_pad

    PHP Code:
    <?php
    $num 
    9;
    echo 
    str_pad($num5"0"STR_PAD_LEFT);

    $num 17;
    echo 
    str_pad($num5"0"STR_PAD_LEFT);
    ?>
    Last edited by manavo11; Apr 23rd, 2008 at 06:52 PM.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: how to add 0's to a number

    PHP Code:
    $num 5;
    $zeros "0000";

    echo 
    $zeros.$num;

    $num 17;
    $zeros "000";

    echo 
    $zeros.$num

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: how to add 0's to a number

    $r = sprintf('%05d', $number);

Posting Permissions

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



Click Here to Expand Forum to Full Width