Skip to content

Commit

Permalink
fixed last number leading zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
aishek committed Dec 13, 2013
1 parent 1c797ee commit e6ce9ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions jquery.animateNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
throw new Error('jquery.animateNumber requires jQuery 1.8.0 or higher');
}

var reverse = function(value) {
return value.split('').reverse().join('');
};

var defaults = {
numberStep: function(now, tween) {
var floored_number = Math.floor(now),
Expand Down Expand Up @@ -97,11 +101,11 @@
};

// remove precending zeros
var last = number_parts[number_parts.length - 1];
number_parts[number_parts.length - 1] = parseInt(last);
var last = reverse(number_parts[number_parts.length - 1]);
number_parts[number_parts.length - 1] = reverse(parseInt(last).toString());

separated_number = number_parts.join(separator);
separated_number = separated_number.split('').reverse().join('');
separated_number = reverse(separated_number);
}

target.prop('number', now).text(separated_number);
Expand Down
6 changes: 3 additions & 3 deletions jquery.animateNumber.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e6ce9ba

Please sign in to comment.