A JavaScript utility for rounding numbers to a specific number of decimal places with configurable rounding rules.
round-to is a JavaScript library for rounding numbers to a specific number of decimal places with configurable rounding rules. It solves the problem of inconsistent or limited rounding in native JavaScript methods by providing precise control over rounding behavior, including support for negative precision and multiple rounding algorithms.
JavaScript developers who need reliable and flexible number rounding for financial calculations, data processing, or UI formatting where precision and rounding rules matter.
Developers choose round-to because it offers a comprehensive set of rounding options in a lightweight package, handling edge cases like banker's rounding and infinite precision that are not covered by built-in methods like `toFixed` or `Math.round`.
Round a number to a specific number of decimal places: 1.234 → 1.2
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports rounding to any decimal place, including negative precision for rounding to tens or hundreds, and handles infinite precision to preserve numbers, as shown with examples like roundTo(1234.56, -2) returning 1200.
Offers six configurable rounding rules, such as banker's rounding ('toNearestOrEven') and always up/down, providing precise control over rounding behavior for diverse use cases like financial calculations.
Provides intuitive functions like roundTo, roundToUp, and roundToDown with clear documentation, making it easy to integrate and use in code without complex setup.
Correctly manages scenarios like Infinity as precision and various rounding rules for negative numbers, as demonstrated in the README with examples such as roundTo(-5.5, 0) returning -6 with default rounding.
Does not include other mathematical operations or support for non-number types, so for broader needs like big integer handling or complex arithmetic, additional libraries are required.
As a library, it adds overhead compared to using native JavaScript methods directly, which could be a concern in high-performance loops or environments with strict bundle size constraints.
Focuses on standard JavaScript numbers and does not mention support for BigInt or other numeric types, limiting its use in applications requiring precision beyond standard floating-point numbers.