You are here: irt.org | FAQ | JavaScript | Number | Q183 [ previous next ]
To format 2 as 02 I use the following JavaScript function:
<script language="JavaScript"><!-- function padout(number) { return (number < 10) ? '0' + number : number; } alert(padout(2)); //--></script>
To format 2 as 00002 I would recommend something like:
<script language="JavaScript"><!-- function pad(number,length) { var str = '' + number; while (str.length < length) str = '0' + str; return str; } alert(pad(2,5)); //--></script>