GitShow/sindresorhus/round-to
sindresorhus

round-to

Round a number to a specific number of decimal places: 1.234 → 1.2

by sindresorhus
Star on GitHubForknpm

JavaScript

159 stars10 forks8 contributorsQuiet · 9mo agoSince 2015v7.0.0MIT

Meet the team

See all 8 on GitHub →
sindresorhus
sindresorhus19 contributions
Richienb
Richienb5 contributions
amrali-eg
amrali-eg2 contributions
BendingBender
BendingBender1 contribution
ruipneves
ruipneves1 contribution
SamVerschueren
SamVerschueren1 contribution
sebastiansandqvist
sebastiansandqvist1 contribution
yvele
yvele1 contribution

Languages

View on GitHub →
JavaScript97.5%
TypeScript2.5%

Commit activity

Last 12 weeks · 0 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
71
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent fixes

View closed PRs →
yvele
Rounding negative number with fractional portion being exactly 0.5ClosedIssue

must be consistent with when dealing with fractional portion being exactly 0.5: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round#description If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +∞. This differs from many languages' functions, which often round half-increments away from zero, giving a different result in the case of negative numbers with a fractional part of exactly 0.5. I suggest that this should be the behavior a JavaScript developer should expect: Previous discussions: https://github.com/sindresorhus/round-to/issues/6 https://github.com/sindresorhus/round-to/pull/8 https://github.com/sindresorhus/round-to/issues/28 (about NOT returning values rounded to -0) Note also that's how Lodash works: https://github.com/lodash/lodash/issues/4529#issuecomment-547270175 See also https://en.wikipedia.org/wiki/Rounding#Comparison_of_approaches_for_rounding_to_an_integer I think the exact description is "Half Up (toward +∞)". !Screenshot 2023-08-09 at 09 26 18

yvele · 9mo ago
yvele
-0 and negative high precision values?ClosedIssue

Is it on purpose to round to instead of ? 🤔 Shouldn't be better to never round to but instead 🤔 See my PR that add unit tests with high precision values: https://github.com/sindresorhus/round-to/pull/27

yvele · 9mo ago
Richienb
Add note for using toFixedMergedPR
Richienb · 10mo ago
Structured data for AI agents

Repository: sindresorhus/round-to. Description: Round a number to a specific number of decimal places: 1.234 → 1.2 Stars: 159, Forks: 10. Primary language: JavaScript. Languages: JavaScript (97.5%), TypeScript (2.5%). License: MIT. Latest release: v7.0.0 (9mo ago). Open PRs: 0, open issues: 0. Last activity: 9mo ago. Community health: 71%. Top contributors: sindresorhus, Richienb, amrali-eg, BendingBender, ruipneves, SamVerschueren, sebastiansandqvist, yvele.

·@ofershap

Replace github.com with gitshow.dev