# evm-bn

> Convert fixed-point numbers to ethers big numbers and vice-versa

Latest version **1.1.2** (published 2022-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install evm-bn
pnpm add evm-bn
yarn add evm-bn
bun add evm-bn
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2022-07-26 |
| First published | 2021-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Paul Razvan Berg |
| Maintainers | paulrberg |
| Keywords | bignumber, blockchain, ethereum, ethers, evm, javascript, number-formatting |

## Links

- npm: https://www.npmjs.com/package/evm-bn
- npm.io page: https://npm.io/package/evm-bn

## Dependencies (2)

- [from-exponential](https://npm.io/package/from-exponential.md) ^1.1.1
- [@ethersproject/bignumber](https://npm.io/package/@ethersproject/bignumber.md) ^5.5.0

## 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.1.2 (latest) — 2022-07-26
- 1.1.1 — 2021-10-27
- 1.1.0 — 2021-10-26
- 1.0.1 — 2021-09-29
- 1.0.0 — 2021-09-27

## README

# Evm Bn [![GitHub Actions][gha-badge]][gha] [![Coverage Status][coveralls-badge]][coveralls] [![Styled with Prettier][prettier-badge]][prettier] [![License: MIT][license-badge]][license]

[gha]: https://github.com/paulrberg/evm-bn/actions
[gha-badge]: https://github.com/paulrberg/evm-bn/actions/workflows/ci.yml/badge.svg
[coveralls]: https://coveralls.io/github/paulrberg/evm-bn
[coveralls-badge]: https://coveralls.io/repos/github/paulrberg/evm-bn/badge.svg?branch=main
[prettier]: https://prettier.io
[prettier-badge]: https://img.shields.io/badge/Code_Style-Prettier-ff69b4.svg
[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg

Convert fixed-point numbers to [ethers](https://github.com/ethers-io/ethers.js) big numbers and vice-versa. This is
useful for [EVM](https://ethereum.org)-related projects, since 1 ETH is 1e18 wei.

- Accepts scientific notation.
- Limits the precision to 78 digits.
- Enforces 60 integer digits and 18 fractional digits.
- Designed to be used alongside [@ethersproject/bignumber](https://github.com/ethers-io/ethers.js/tree/master/packages/bignumber).
- Slices the fractional digits automatically at position `n + 1` and above, with `n` the number of decimals, rounding down in the process.

## Install

With yarn:

```sh
$ yarn add evm-bn
```

Or npm:

```sh
$ npm install evm-bn
```

## Usage

### To Bn

```ts
import type { BigNumber } from "@ethersproject/bignumber";
import { toBn } from "evm-bn";

// 3141500000000000000
const foo: BigNumber = toBn("3.1415");

// 115792089237316195423570985008687907853269984665640564039457584007913129639935
const bar: BigNumber = toBn("115792089237316195423570985008687907853269984665640564039457.584007913129639935");

// 100000000000000
const baz: BigNumber = toBn("100e6", 6);
```

### From Bn

```ts
import type { BigNumber } from "@ethersproject/bignumber";
import { fromBn } from "evm-bn";

// 3.1415
const foo: BigNumber = fromBn(BigNumber.from("3141500000000000000"));

// 115792089237316195423570985008687907853269984665640564039457.584007913129639935
const bar: BigNumber = fromBn(
  BigNumber.from("115792089237316195423570985008687907853269984665640564039457584007913129639935"),
);

// 100000000
const baz: BigNumber = fromBn(BigNumber.from("100000000000000"), 6);
```

## Contributing

Feel free to dive in! [Open](https://github.com/paulrberg/evm-bn/issues/new) an issue, [start](https://github.com/paulrberg/evm-bn/discussions/new) a discussion or submit a PR.

### Set Up

Clone the repositories and install the dependencies:

```bash
$ yarn install
```

Now you can start making changes.

## License

[MIT](./LICENSE.md) © Paul Razvan Berg

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