Re: [PHP] pad numbers

2003-10-10 Thread Wang Shengli
Sorry,
it should be
$dd = sprintf("%02d", $d);
will generate $dd = "05";

If you want 005;
use
$dd =sprintf("%03d", $d);

if you want XXX5;
use
$dd = sprintf("%X4d", $d);

- Original Message - 
From: "Diana Castillo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 10, 2003 10:44 AM
Subject: [PHP] pad numbers


> is there a function to convert a number that has less than two digits into
a
> number with a leading zero?
> for instance, to convert a "5" to "05" but to leave a "11" as "11"
> thanks,
> Diana
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] pad numbers

2003-10-10 Thread Wang Shengli
$d = 5;
$dd = sprintf("%0d", $d);
will do -- $dd = "05";

- Original Message - 
From: "Diana Castillo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 10, 2003 10:44 AM
Subject: [PHP] pad numbers


> is there a function to convert a number that has less than two digits into
a
> number with a leading zero?
> for instance, to convert a "5" to "05" but to leave a "11" as "11"
> thanks,
> Diana
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] pad numbers

2003-10-10 Thread Marek Kilimajer
str_pad --  Pad a string to a certain length with another string

Diana Castillo wrote:

is there a function to convert a number that has less than two digits into a
number with a leading zero?
for instance, to convert a "5" to "05" but to leave a "11" as "11"
thanks,
Diana
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] pad numbers

2003-10-10 Thread Tom Rogers
Hi,

Saturday, October 11, 2003, 12:44:38 AM, you wrote:
DC> is there a function to convert a number that has less than two digits into a
DC> number with a leading zero?
DC> for instance, to convert a "5" to "05" but to leave a "11" as "11"
DC> thanks,
DC> Diana


$num = sprintf("%02d",$num); is what you need

-- 
regards,
Tom

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



RE: [PHP] pad numbers

2003-10-10 Thread Susan Ator
The way I have done it is to check the length of the number and if it is 1
then add the 0 myself.

my $len = length($mm);
if ($len eq 1) { $mm = "0$mm"; }

Susan

-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]
Sent: Friday, October 10, 2003 10:45 AM
To: [EMAIL PROTECTED]
Subject: [PHP] pad numbers


is there a function to convert a number that has less than two digits into a
number with a leading zero?
for instance, to convert a "5" to "05" but to leave a "11" as "11"
thanks,
Diana

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

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