Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Node.js
  3. round-to

round-to

MITJavaScriptv7.0.0

A JavaScript utility for rounding numbers to a specific number of decimal places with configurable rounding rules.

GitHubGitHub
159 stars10 forks0 contributors

What is round-to?

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.

Target Audience

JavaScript developers who need reliable and flexible number rounding for financial calculations, data processing, or UI formatting where precision and rounding rules matter.

Value Proposition

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`.

Overview

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

Use Cases

Best For

  • Financial applications requiring banker's rounding (to nearest even)
  • Data processing where consistent rounding rules are critical
  • UI components that format numbers with specific decimal precision
  • Scientific calculations needing control over rounding direction
  • Converting floating-point numbers to fixed decimal representations
  • Handling rounding for negative numbers and edge cases like Infinity

Not Ideal For

  • Projects that only need string output for display and can rely on `toFixed()` without number rounding
  • Performance-critical applications where the overhead of a library call over native methods is unacceptable
  • Systems requiring comprehensive mathematical operations beyond rounding, such as arbitrary-precision arithmetic

Pros & Cons

Pros

Flexible Precision Range

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.

Multiple Rounding Algorithms

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.

Clean and Simple API

Provides intuitive functions like roundTo, roundToUp, and roundToDown with clear documentation, making it easy to integrate and use in code without complex setup.

Edge Case Handling

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.

Cons

Limited to Rounding Only

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.

Slight Performance Cost

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.

No BigInt or Special Support

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.

Frequently Asked Questions

Quick Stats

Stars159
Forks10
Contributors0
Open Issues0
Last commit10 months ago
CreatedSince 2015

Tags

#es-modules#number-formatting#nodejs#javascript#rounding

Built With

J
JavaScript

Included in

Node.js65.5k
Auto-fetched 20 hours ago

Related Projects

unique-randomunique-random

Generate random numbers that are consecutively unique

Stars119
Forks16
Last commit2 years ago
random-intrandom-int

Generate a random integer

Stars91
Forks16
Last commit10 months ago
random-floatrandom-float

Generate a random float

Stars37
Forks8
Last commit5 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub