# smart-round

> Round big numbers with arbitrary precision

Latest version **3.0.1** (published 2025-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install smart-round
pnpm add smart-round
yarn add smart-round
bun add smart-round
```

## Health

**Score 45/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2025-09-15 |
| First published | 2018-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 78.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Gabriel Montes |
| Maintainers | gabmontes, gndelia |
| Keywords | big.js, decimals, precision, round, typescript |

## Links

- npm: https://www.npmjs.com/package/smart-round
- Repository: https://github.com/bloq/smart-round
- Homepage: https://github.com/bloq/smart-round#readme
- Issues: https://github.com/bloq/smart-round/issues
- npm.io page: https://npm.io/package/smart-round

## Dependencies (1)

- [big.js](https://npm.io/package/big.js.md) 7.0.1

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2025-09-15
- 3.0.0 — 2025-04-29
- 2.0.0 — 2025-02-21
- 1.0.0 — 2018-07-19

## README

# smart-round

![NPM Version](https://img.shields.io/npm/v/smart-round)![npm bundle size](https://img.shields.io/bundlephobia/minzip/smart-round)

Round big numbers with arbitrary precision.

## Installation

```sh
npm install --save smart-round
```

## Usage

The module exports a function that let you initialize a rounder function.

### `smartRound(maxPrecision, minDecimals, maxDecimals)`

`maxPrecision`: Amount of significant digits to return.
`minDecimals`: Minimum amount of decimals to return.
`maxDecimals`: Maximum amount of decimals to return.

### `rounder(number, shouldFormat)`

`input`: The value to round. Accepts any type supported by [`bignumber.js`](https://github.com/MikeMcl/bignumber.js) package.
`options`: An optional object to customize the formatting:

- `options.locale`: Optional. Format used to format when `options.shouldFormat`is true. Defaults to `en-US`.
- `options.roundingMode` Optional. Specifies the rounding method. Accepted values: `round-up`, `round-down` ,`round-ceil`, `round-floor`, `round-half-up`, `round-half-down`, `round-half-even`, `round-half-ceil`, `round-half-floor`. Defaults to `round-half-up`.
- `options.shouldFormat`: Optional. Defaults to `false`. Indicates whether the string should be formatted using [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat),

## Example

```js
import { smartRound } from "smart-round";

const rounder1 = smartRound(6, 0, 6);

console.log(rounder1("1234.56789")); // '1234.57'
console.log(rounder1("1234.56789", { shouldFormat: true })); // '1,234.56'

const rounder2 = smartRound(4, 2, 6);

console.log(rounder2("1234", { shouldFormat: true })); // '1,234.00'
console.log(rounder2("0.000123456", { shouldFormat: true })); // '0.000123'
```

---
_Source: https://npm.io/package/smart-round · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
