Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with negative numbers #8

Merged
merged 6 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function round(fn, x, precision) {
var exponentNeg = precision > 0 ? 'e-' : 'e';
precision = Math.abs(precision);

if (fn === 'round') {
return Number(Math.sign(x) * (Math[fn](Math.abs(x) + exponent + precision) + exponentNeg + precision));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math[fn] => Math.round. We already know what the fn is.

}
return Number(Math[fn](x + exponent + precision) + exponentNeg + precision);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"increment"
],
"dependencies": {
"number-is-integer": "^1.0.0"
"number-is-integer": "^1.0.1"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do unrelated changes. This change also makes no difference.

},
"devDependencies": {
"ava": "*",
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test('roundTo()', t => {
t.is(fn(1.005, 2), 1.01);
t.is(fn(1.005, 0), 1);
t.is(fn(111.1, -2), 100);
t.is(fn(-0.375, 2), -0.38);
});

test('roundTo.up()', t => {
Expand All @@ -17,6 +18,7 @@ test('roundTo.up()', t => {
t.is(fn.up(1.004, 2), 1.01);
t.is(fn.up(1.111, 0), 2);
t.is(fn.up(111.1, -2), 200);
t.is(fn.up(-0.375, 2), -0.37);
});

test('roundTo.down()', t => {
Expand All @@ -26,4 +28,5 @@ test('roundTo.down()', t => {
t.is(fn.down(1.006, 2), 1.00);
t.is(fn.down(1.006, 0), 1);
t.is(fn.down(111.6, -2), 100);
t.is(fn.down(-0.375, 2), -0.38);
});