# round_to

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

Latest version **1.0.0** (published 2017-10-13) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install round_to
pnpm add round_to
yarn add round_to
bun add round_to
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-10-13 |
| First published | 2017-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Yoginth |
| Maintainers | yoginth |
| Keywords | round, number, num, decimal, places, ceil, floor, math, increment |

## Links

- npm: https://www.npmjs.com/package/round_to
- Repository: https://github.com/yoginth/roundto
- Homepage: https://github.com/yoginth/roundto#readme
- Issues: https://github.com/yoginth/roundto/issues
- npm.io page: https://npm.io/package/round_to

## 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

- 1.0.0 (latest) — 2017-10-13

## README

# round_to [![Build Status](https://travis-ci.org/yoginth/round_to.svg?branch=master)](https://travis-ci.org/yoginth/round_to)

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


## Install

```
$ npm install --save round_to
```


## Usage

```js
const roundTo = require('round-to');

roundTo(1.234, 2);
//=> 1.23

roundTo.up(1.234, 2);
//=> 1.24

roundTo.down(1.234, 2);
//=> 1.23
```

Numbers are rounded to a specific number of significant figures. Specifying a negative precision will round to any number of places to the left of the decimal.

```js
roundTo(1234.56, -2);
//=> 1200
```

## API

### roundTo(value, precision)

Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round).

### roundTo.up(value, precision)

Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil).

### roundTo.down(value, precision)

Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor).

#### value

Type: `number`

#### precision

Type: `number` (integer)

Number of decimal places.


## License

MIT © [Yoginth](http://yoginth.ml)

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