Library code snippets

Output number with leading zeros

Here's simple example using the printf function to output a number with leading zeros.

<?
$number = 15;
printf("%05d", $number);
?>

Comments

  1. 23 Dec 2006 at 19:09
    It seems that irt doesn't work all the time: example

    $y=decbin(3327);
    echo $y."<br>";
    $z = sprintf("%012d", $y);
    echo $z;

    I get
    3327
    110011111111
    002147483647

    Last row should be the same as the second one

    Do you have an idea why?















  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Output number with leading zeros.

Leave a comment

Sign in or Join us (it's free).

 altphpfaq

Related discussion

Related podcasts

  • EarthClassMail.com - Moving from LAMP to .NET 3.5

    Scott chats with Matt Davis, architect at EarthClassMail.com, about their move from a LAMP stack (Linux/Apache/mysql/PHP) to .NET 3.5. What's working, what's not, and what kinds of issues are they running into as their architect their solution.

Events coming up

  • Dec 3

    The Auckland PHP December meetup

    Auckland, New Zealand

    Topic: Magento E-Commerce platform Speaker: Robert Popovic, LERO9, Robert is the Technical Director and co-founder of LERO9. Robert attended the Electrotechnical Faculty at The University of Belgrade where he graduated with a Masters in Computer Science and Information Technology. Robert has worked exclusively in the field of web and software development throughout his career.

Want to stay in touch with what's going on? Follow us on twitter!