2

I use jquery animate for incremente random number 0001 to 1000 but if number is 0077 the final number is 77 what is the solution for have format like 0077 plz ?

Thanks you

var $date = $("#date");
  $({someValue: 0000}).animate({someValue: 0077}, {
      duration: 1000,
      easing:'swing', 
      step: function() { 
          $date.text(Math.round(this.someValue));
      }
  });
danmullen
  • 2,556
  • 3
  • 20
  • 28

2 Answers2

2

This may meet your needs:

$date.text(("0000" + Math.round(this.someValue)).slice(-4));

For example:

("0000" + 77).slice(-4);

gives 0077.

Bruno Calza
  • 2,732
  • 2
  • 23
  • 25
2

you can use a function like this

function fill (N) {
  N = N.toString();
  return N.length < 4 ? fill("0" + str, 4) : N;
}

the number 4 is the number of digits that need your string like 4 in your case...

xploshioOn
  • 4,035
  • 2
  • 28
  • 37