Grow your CSS skills. Land your dream job.

Last updated on:

Force Leading Zero

  function forceLeadingZero($int) {
    return (int)sprintf('%02d',$int);

Forces leading zero to integers.

was | now

1 | 01
2 | 02
3 | 03

10 | 10
100 | 100
99 | 99

Reference URL


  1. LM
    Permalink to comment#


  2. LM
    Permalink to comment#

    str_pad($input, 2, “0”, STR_PAD_LEFT);

  3. str_pad is probably more semantically accurate, but sprintf() is faster.

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

<div>Example code</div>

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".