# @glif/filecoin-number

> a javascript package to handle Filecoin numbers like Fil and AttoFil

Latest version **4.0.0** (published 2025-04-25) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install @glif/filecoin-number
pnpm add @glif/filecoin-number
yarn add @glif/filecoin-number
bun add @glif/filecoin-number
```

## Health

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

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-04-25 |
| First published | 2020-10-05 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 218.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Infinite Scroll <squad@infinitescroll.org> (https://infinitescroll.org) |
| Maintainers | schwartzz8990, bret, glifbot |

## Links

- npm: https://www.npmjs.com/package/@glif/filecoin-number
- Repository: https://github.com/glifio/modules/tree/primary/packages/filecoin-number
- npm.io page: https://npm.io/package/@glif/filecoin-number

## Dependencies (3)

- [bent](https://npm.io/package/bent.md) 7.3.12
- [bn.js](https://npm.io/package/bn.js.md) ^5.2.1
- [bignumber.js](https://npm.io/package/bignumber.js.md) 9.0.1

## Recent versions

- 4.0.0 (latest) — 2025-04-25
- 3.0.15 — 2024-09-10
- 3.0.8 — 2024-06-26
- 3.0.3 — 2024-02-21
- 3.0.2 — 2024-02-06
- 3.0.0 — 2024-01-15
- 2.0.74 — 2023-12-06
- 2.0.72 — 2023-11-29
- 2.0.71 — 2023-11-24
- 2.0.70 — 2023-10-20
- 2.0.69 — 2023-08-14
- 2.0.68 — 2023-08-11
- 2.0.67 — 2023-06-07
- 2.0.66 — 2023-06-01
- 2.0.65 — 2023-05-29
- … 39 more at https://npm.io/package/@glif/filecoin-number/versions

## README

# Filecoin number

A wrapper class built around javascript's [bignumber](https://github.com/MikeMcl/bignumber.js). Most questions are best answered from the bignumber readme and docs.

## FilecoinNumber Usage

```js
import { FilecoinNumber, Converter } from '@glif/filecoin-number'

// pass a valid bignumber argument, and a denomination ('fil', 'picofil', or 'attofil') to the constructor.
const filecoinNumber = new FilecoinNumber('10000', 'attofil')

// filecoinNumber is an instance of BigNumber, so you can use it as such
filecoinNumber.multiply(7)

// it comes with 2 additional instance methods for showing the filecoin number as a string in attofil or fil
const inPicoFil = filecoinNumber.toPicoFil()
const inAttoFil = filecoinNumber.toAttoFil()
const inFil = filecoinNumber.toFil()
```

## Converter Usage

```js
// Use the Converter to convert currencies
const optionalConfig = {
  apiURL: 'https://coinmarketproxy.com',
  apiKey: 'RIP Kobe',
}

const USDConverter = new Converter('USD', optionalConfig)

await USDConverter.cacheConversionRate()

const USD = USDConverter.fromFIL(1)
const FIL = USDConverter.toFIL(1)

// fromFIL and toFIL take numbers, strings, BigNumbers, and FilecoinNumbers as valid args
const USD = USDConverter.fromFIL(1)
const USD = USDConverter.fromFIL('1')
const USD = USDConverter.fromFIL(new BigNumber(1))
const USD = USDConverter.fromFIL(new FilecoinNumber('1', 'fil'))
```

## Running tests locally

We use an APIADDR environment variable in the tests. You can either:
(a) add the APIADDR environment variable locally, or
(b) use a secrets.js file to export private information

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