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

Allow negative decimal precision to round to 10s, 100s, etc #329

Closed
jefffriesen opened this issue Nov 30, 2014 · 4 comments · Fixed by #332
Closed

Allow negative decimal precision to round to 10s, 100s, etc #329

jefffriesen opened this issue Nov 30, 2014 · 4 comments · Fixed by #332
Labels

Comments

@jefffriesen
Copy link

Currently we have:

_('2.556').toNumber(1)
=> 2.6

What would be really nice would be able to round up beyond the decimal point. For example:

_(234).toNumber(-1)
=>230
_(234).toNumber(-2)
=>200

This is how d3 and some other library handle rounding. Currently trying it throws this error RangeError: toFixed() digits argument must be between 0 and 20

This could also work with _.numberFormat().

Does this seem like a good fit to this library?

@megawac
Copy link
Contributor

megawac commented Nov 30, 2014

+1 I'll make a pr for this tomorrow morning

megawac added a commit to megawac/underscore.string that referenced this issue Nov 30, 2014
@stoeffel
Copy link
Collaborator

+1 looks nice. I will look into this next week and review the PR from @megawac

@jefffriesen
Copy link
Author

Any chance to work on this yet?
Thanks!

megawac added a commit to megawac/underscore.string that referenced this issue Dec 23, 2014
@jefffriesen
Copy link
Author

This is great. Thanks!

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

Successfully merging a pull request may close this issue.

3 participants