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

Rounding 5 with negative numbers #6

Closed
Railslide opened this issue Jun 1, 2016 · 4 comments · Fixed by #8
Closed

Rounding 5 with negative numbers #6

Railslide opened this issue Jun 1, 2016 · 4 comments · Fixed by #8

Comments

@Railslide
Copy link

When rounding negative numbers, 5 behaves differently from what I would expect / how it works in other programming languages.

roundTo(0.375, 2);
// 0.38

roundTo(-0.375, 2);
// -0.37 (I was expecting -0.38)

Not sure if that's by design or not.

@sindresorhus
Copy link
Owner

Yeah, that seems like a bug.

@SamVerschueren
Copy link
Contributor

What is the expected result of the following expressions?

roundTo.up(-0.375, 2);
roundTo.down(-0.375, 2);

Does up means more negative and thus -0.38 and down more positive and thus -0.37 or the other way around?

@Railslide
Copy link
Author

Railslide commented Jun 7, 2016

I would expect

roundTo.up(-0.375, 2);
// -0.37
roundTo.down(-0.375, 2);
// -0.38

Actually, it looks like Math.round is the culprit, since:

Math.round(-0.5);
// 0
Math.round(0.5):
// 1

@sindresorhus
Copy link
Owner

Fixed by #8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants