R: [PHP] Padding number with zeros
| From: | (Delbono) | Date: | Sat, 16 Dec 2000 11:02:11 +0000 |
| Subject: | R: [PHP] Padding number with zeros | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30658@lists.php.net to get a copy of this message | ||
If you use PHP4 and you always want the number to be 4 chars lenght:
$numbLen = str_len($number); // check how many chars is the number you have
$zeroAdd = $numbStandard - $numbLen; // 0000 - 25 = 2 (2 zeroes to be added)
$numb = str_repeat("0", $zeroAdd) . $number; // print zeroes to reach the
standard 4 chars lenght
Nicola-
> Hello!
> How do I pad a number to a given number of zeros?
> ie.:
> 25 to 0025
> 134 to 0134
> 1 to 0001
> ?
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>