Pad a number with leading zeros - Javascript Number Operation

Javascript examples for Number Operation:Number Format


Pad a number with leading zeros

Demo Code

ResultView the demo in separate window

      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w w w . j  a  v  a  2  s  .c  o  m
function pad(input) {
    var BASE = "0000";
    return input ? BASE .substr(0, 4 - Math.ceil(input / 10)) + input : BASE;


Related Tutorials