Skip to content

Commit

Permalink
fix: round subscriber count
Browse files Browse the repository at this point in the history
fixes #711
  • Loading branch information
fent committed Sep 25, 2020
1 parent 0ecb0c4 commit 4d30a2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/util.js
Expand Up @@ -375,8 +375,8 @@ exports.parseAbbreviatedNumber = string => {
if (match) {
let [, num, multi] = match;
num = parseFloat(num);
return multi === 'M' ? num * 1000000 :
multi === 'K' ? num * 1000 : num;
return Math.round(multi === 'M' ? num * 1000000 :
multi === 'K' ? num * 1000 : num);
}
return null;
};
Expand Down
3 changes: 2 additions & 1 deletion test/util-test.js
Expand Up @@ -575,10 +575,11 @@ describe('util.parseAbbreviatedNumber', () => {
it('Parses abbreviated numbers', () => {
assert.strictEqual(util.parseAbbreviatedNumber('41K'), 41000);
assert.strictEqual(util.parseAbbreviatedNumber('1.5M'), 1500000);
assert.strictEqual(util.parseAbbreviatedNumber('8.19K '), 8190);
});
it('Parses non-abbreviated numbers', () => {
assert.strictEqual(util.parseAbbreviatedNumber('1234'), 1234);
assert.strictEqual(util.parseAbbreviatedNumber('123.456'), 123.456);
assert.strictEqual(util.parseAbbreviatedNumber('123.456'), 123);
});
it('Returns `null` when given non-number', () => {
assert.strictEqual(util.parseAbbreviatedNumber('abc'), null);
Expand Down

0 comments on commit 4d30a2a

Please sign in to comment.