Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created February 22, 2014 10:16
Show Gist options
  • Save lmartins/9151584 to your computer and use it in GitHub Desktop.
Save lmartins/9151584 to your computer and use it in GitHub Desktop.
Add leading zeros to a number if applicable
pad = (num) ->
('0'+num).slice(-2)
console.log pad(8)
console.log pad(12)
@muratcorlu
Copy link

An alternative:

pad = (num) ->
    "0#{ num }".slice(-2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment