Javascript examples for Number Operation:Number Format
Prepend a zero in front of any number below 10
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {// ww w .j a v a 2 s. c o m function pad(n) { if (n < 10) return "0" + n; return n; } console.log(pad(8)); console.log(pad(11)); }); </script> </head> <body> </body> </html>