Number Spinner Animation

by Jithin Raj P R

HTML

<label id="value">1700000</label>

JavaScript

Number.prototype.formatMoney = function(c, d, t) {
  var n = this,
    c = isNaN(c = Math.abs(c)) ? 2 : c,
    d = d == undefined ? "." : d,
    t = t == undefined ? "," : t,
    s = n < 0 ? "-" : "",
    i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
    j = (j = i.length) > 3 ? j % 3 : 0;
  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
var myDiv = document.getElementById("value");
var myDivVal = parseInt(myDiv.innerHTML);
var totalSeconds = 1000;

var setIn = setInterval(function() {
  if (totalSeconds <= myDivVal) {
    totalSeconds = totalSeconds + ((10 / 100) * totalSeconds);
    if (totalSeconds <= myDivVal) {
      myDiv.innerHTML = (totalSeconds).formatMoney(0, '.', ',');
    } else {
      myDiv.innerHTML = (myDivVal).formatMoney(0, '.', ',');
      clearInterval(setIn);
    }
  }
}, 10);