Number formating: 1 -> '01'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mr_burns

    #1

    Number formating: 1 -> '01'

    Hi,

    I am tryin to format a number from, for example, 1 to '01'. How is this done? Cheers

    Burnsy
  • Michael Fesser

    #2
    Re: Number formating: 1 -> '01'

    .oO(mr_burns)
    [color=blue]
    >I am tryin to format a number from, for example, 1 to '01'. How is this done?[/color]



    Micha

    Comment

    • nice.guy.nige

      #3
      Re: Number formating: 1 -> '01'

      While the city slept, mr_burns (bissatch@yahoo .co.uk) feverishly typed...
      [color=blue]
      > I am tryin to format a number from, for example, 1 to '01'. How is
      > this done? Cheers[/color]

      printf("<p>num with 2 digits (leading zero): %02d</p>", $num);

      Demo'd here: http://www.nigenet.org.uk/stuff/formatNum.php

      Hope that helps,
      Nige

      --
      Nigel Moss
      This is the personal website of Nigel Moss - Web and software developer, musician, photographer. It is home to my CV, portfolio, general info and more.

      Mail address not valid. nigel@DOG.nigen et.org.uk, take the DOG. out!
      In the land of the blind, the one-eyed man is very, very busy!


      Comment

      • Michael Austin

        #4
        Re: Number formating: 1 -&gt; '01'

        mr_burns wrote:
        [color=blue]
        > Hi,
        >
        > I am tryin to format a number from, for example, 1 to '01'. How is this done? Cheers
        >
        > Burnsy[/color]

        From the PHP docs:

        " kennyc at horizondigital dot com
        14-Jun-2002 07:57
        ONELINE LEADING ZERO ADDER: I kept getting frustrated by php's weak number
        formatting functions and using the recursive leading zero adders that I've seen
        in other people code, so here's my quick and easy oneliner for adding leading
        zero's to any number:

        Two digit space:
        substr($num+100 ,1);
        0=00
        5=05
        23=23
        3.14=03.14

        Four digit space:
        substr($num+100 00,1);
        0=0000
        5=0005
        23=0023
        256=0256
        4096=4096
        98.6=0098.6

        You may want to check first to be sure that your number dosen't already exceed
        it's character size!"

        quite ingenious I might add.. I actually wrote this a couple of hours ago, just
        forgot to send it... sorry for the delay...

        --
        Michael Austin.
        Consultant - NOT Available.
        Donations STILL welcomed. Http://www.firstdbasource.com/donations.html
        :)

        Comment

        • Michael Fesser

          #5
          Re: Number formating: 1 -&gt; '01'

          .oO(Michael Austin)
          [color=blue]
          > From the PHP docs:
          >
          >" kennyc at horizondigital dot com
          >14-Jun-2002 07:57
          >ONELINE LEADING ZERO ADDER: [...][/color]

          Nice little hack, but not necessary anymore.

          Micha

          Comment

          Working...