Skip to content

Commit

Permalink
fixing negative grouping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Perkins committed Nov 7, 2017
1 parent c4b233d commit 497c3cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
13 changes: 7 additions & 6 deletions countUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var CountUp = function(target, startVal, endVal, decimals, duration, options) {

var self = this;
self.version = function () { return '1.9.2'; };
self.version = function () { return '1.9.3'; };

// default options
self.options = {
Expand Down Expand Up @@ -72,19 +72,20 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
}

function formatNumber(num) {
num = num.toFixed(self.decimals);
var neg = (num < 0),
x, x1, x2, x3, i, len;
num = Math.abs(num).toFixed(self.decimals);
num += '';
var x, x1, x2, x3, i, l;
x = num.split('.');
x1 = x[0];
x2 = x.length > 1 ? self.options.decimal + x[1] : '';
if (self.options.useGrouping) {
x3 = '';
for (i = 0, l = x1.length; i < l; ++i) {
for (i = 0, len = x1.length; i < len; ++i) {
if (i !== 0 && ((i % 3) === 0)) {
x3 = self.options.separator + x3;
}
x3 = x1[l - i - 1] + x3;
x3 = x1[len - i - 1] + x3;
}
x1 = x3;
}
Expand All @@ -97,7 +98,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
return self.options.numerals[+w];
})
}
return self.options.prefix + x1 + x2 + self.options.suffix;
return (neg ? '-' : '') + self.options.prefix + x1 + x2 + self.options.suffix;
}
// Robert Penner's easeOutExpo
function easeOutExpo(t, b, c, d) {
Expand Down
13 changes: 7 additions & 6 deletions dist/countUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var CountUp = function(target, startVal, endVal, decimals, duration, options) {

var self = this;
self.version = function () { return '1.9.2'; };
self.version = function () { return '1.9.3'; };

// default options
self.options = {
Expand Down Expand Up @@ -83,19 +83,20 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
}

function formatNumber(num) {
num = num.toFixed(self.decimals);
var neg = (num < 0),
x, x1, x2, x3, i, len;
num = Math.abs(num).toFixed(self.decimals);
num += '';
var x, x1, x2, x3, i, l;
x = num.split('.');
x1 = x[0];
x2 = x.length > 1 ? self.options.decimal + x[1] : '';
if (self.options.useGrouping) {
x3 = '';
for (i = 0, l = x1.length; i < l; ++i) {
for (i = 0, len = x1.length; i < len; ++i) {
if (i !== 0 && ((i % 3) === 0)) {
x3 = self.options.separator + x3;
}
x3 = x1[l - i - 1] + x3;
x3 = x1[len - i - 1] + x3;
}
x1 = x3;
}
Expand All @@ -108,7 +109,7 @@ var CountUp = function(target, startVal, endVal, decimals, duration, options) {
return self.options.numerals[+w];
})
}
return self.options.prefix + x1 + x2 + self.options.suffix;
return (neg ? '-' : '') + self.options.prefix + x1 + x2 + self.options.suffix;
}
// Robert Penner's easeOutExpo
function easeOutExpo(t, b, c, d) {
Expand Down
2 changes: 1 addition & 1 deletion dist/countUp.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "countup.js",
"description": "Animates a numerical value by counting to it",
"version": "1.9.2",
"version": "1.9.3",
"license": "MIT",
"main": "./dist/countUp.min.js",
"repository": {
Expand Down

0 comments on commit 497c3cd

Please sign in to comment.