You can create your own function for this. To format a number, you first need to convert it to a string.
function pad(num, size) { let s = num+""; while (s.length < size) s = "0" + s; return s; }
Typescript
pad(num:number, size:number): string { let s = num+""; while (s.length < size) s = "0" + s; return s; }
Edit: There are several better and more efficient ways to do this. See the discussion in this answer: fooobar.com/questions/20861 / ... (I recommend reading most of the answers provided if you have time)
Update: ECMAScript 2017 now has support for filling in a string
str.padStart(targetLength [, padString]) str.padEnd(targetLength [, padString])
Check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
source share