# chai-bignumber

> Chai assertions for comparing arbitrary-precision decimals using the bignumber.js library

Latest version **3.1.0** (published 2022-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-bignumber
pnpm add chai-bignumber
yarn add chai-bignumber
bun add chai-bignumber
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2022-09-25 |
| First published | 2015-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | António Marques |
| Maintainers | asmarques |
| Keywords | chai, chai-plugin, math, browser, test, arbitrary, precision, arithmetic, big, number, decimal, float, bignumber |

## Links

- npm: https://www.npmjs.com/package/chai-bignumber
- Repository: https://github.com/asmarques/chai-bignumber
- npm.io page: https://npm.io/package/chai-bignumber

## 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.1.0 (latest) — 2022-09-25
- 3.0.0 — 2018-11-17
- 2.0.2 — 2017-11-03
- 2.0.1 — 2017-07-11
- 2.0.0 — 2016-06-10
- 1.0.0 — 2015-11-22
- 0.9.2 — 2015-11-12
- 0.9.1 — 2015-11-01
- 0.9.0 — 2015-11-01

## README

# chai-bignumber

![Build Status](https://github.com/asmarques/chai-bignumber/workflows/CI/badge.svg)

Chai assertions for comparing arbitrary-precision decimals using the [bignumber.js](https://github.com/MikeMcl/bignumber.js) library.

## Installation

```bash
npm install --save-dev chai-bignumber
```

## Usage

```javascript
var chai = require('chai');

//use default BigNumber
chai.use(require('chai-bignumber')());

//use custom BigNumber
chai.use(require('chai-bignumber')(BigNumber));
```

## Assertions

The following assertion methods are provided and will override the existing
builtin assertions if the `bignumber` property is explicitly set as part of
the assertion chain:
- equal/equals/eq
- above/gt/greaterThan
- least/gte/greaterThanOrEqual
- below/lt/lessThan
- most/lte/lessThanOrEqual

The above methods have the following signature: `(value, dp, rm)`.
Where `dp` is an optional argument which specifies the number of decimal places
to round each side of the comparison to (values are not rounded by default),
while `rm` is an optional argument which specifies the
[rounding mode](https://mikemcl.github.io/bignumber.js/#constructor-properties)
as supported by `bignumber.js` (defaults to `BigNumber.ROUND_HALF_UP`).

A set of additional assertion properties is also provided:
- finite
- integer
- negative
- zero

Values can be instances of `number`, `BigNumber` or `string` which can be
converted into a valid number. Only BDD style (`expect` or `should`) assertions
are supported.

## Examples

Methods:

```javascript
var result = new BigNumber('100000000000000000').plus(1);
var expected = '100000000000000001';
result.should.be.bignumber.equal(expected);
expect(result).to.be.bignumber.at.most(expected);
'1000'.should.be.bignumber.lessThan(2000);
```

Methods with rounding:

```javascript
var BigNumber = require('bignumber.js');
(100.343).should.be.bignumber.equal(100.341, 2);
(100.349).should.be.bignumber.equal(100.341, 2, BigNumber.ROUND_DOWN);
```

Properties:

```javascript
(100 / 0).should.not.be.finite;
expect(10).to.be.integer;
(-100).should.be.negative;
expect(1 - 1).to.be.zero;
```

## License

[MIT](LICENSE)

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