# toformat

> Adds a `toFormat` instance method to decimal.js or big.js

Latest version **2.0.0** (published 2017-10-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-10-16 |
| First published | 2016-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | Michael Mclaughlin |
| Maintainers | mikemcl |
| Keywords | format, bignumber, big, number, big.js, decimal.js |

## Links

- npm: https://www.npmjs.com/package/toformat
- Repository: https://github.com/MikeMcl/toFormat
- Homepage: https://github.com/MikeMcl/toFormat#readme
- Issues: https://github.com/MikeMcl/toFormat/issues
- npm.io page: https://npm.io/package/toformat

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

- 2.0.0 (latest) — 2017-10-16
- 1.0.0 — 2016-02-10

## README

# toFormat

Adds a `toFormat` instance method to [big.js](https://github.com/MikeMcl/big.js/) or [decimal.js](https://github.com/MikeMcl/decimal.js/).

## Install

Node.js

```bash
$ npm install toformat
```

Browser

```html
<script src='path/to/big.js'></script>
<script src='path/to/toFormat.js'></script>
```

## Use

### Node.js

```js
Big = require('big')
Big = require('toformat')(Big)

x = new Big(9876.54321)
x.toFormat(2)                       // '9,876.54'

// Three different ways of setting a formatting property
Big.format.decimalSeparator = ','
x.format.groupSeparator: ' '
x.toFormat(1, { groupSize: 2 })    // '98 76,5'
```

### Browser

```js
toFormat(Big)
x = new Big(9876.54321)
x.toFormat(2)                      // '9,876.54'
```

### Further examples:

```js
// The format object added to the Decimal constructor by this library.
Decimal.format = {
  decimalSeparator: '.',
  groupSeparator: ',',
  groupSize: 3,
  secondaryGroupSize: 0,
  fractionGroupSeparator: '',
  fractionGroupSize : 0
}

x.toFormat()                        // 123,456,789.987654321
x.toFormat(2, 1)                    // 123,456,789.98

// Add a format object to a Decimal instance.
x.format = {
  decimalSeparator: ',',
  groupSeparator: '',
}

x.toFormat()                       // 123456789,987654321

format = {
  decimalSeparator: '.',
  groupSeparator: ' ',
  groupSize: 3,
  fractionGroupSeparator: ' ',
  fractionGroupSize : 5
}

// Pass a format object to the method call.
x.toFormat(format)                 // 123 456 789.98765 4321
x.toFormat(4, format)              // 123 456 789.9877
x.toFormat(2, 1, format)           // 123 456 789.98
```

## Test

```bash
$ npm test
```

## Licence

[MIT](LICENCE)

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