note 34471 deleted from function.number-format by didou
| From: | didou@php.net | Date: | Mon, 28 Jul 2003 15:57:25 +0000 |
| Subject: | note 34471 deleted from function.number-format by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52855@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Ok, for those of you writing functions to zero pad, there's a reason they said to "see
sprintf." Want to pad a number to 6 digits?
$nMyNum = 54;
$nPadLength = 6;
$nPadded = sprintf("%0{$nPadLength}d", $nMyNum);
And that's it. One line, no function overhead. For those of you unfamiliar with sprintf and
printf, I suggest you take a look. They both offer quite a few built-in formatting elements that
have been duplicated here.