# decimal

> Simple decimal arithmetic for the browser and node.js!

Latest version **0.0.2** (published 2011-12-25) · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2011-12-25 |
| First published | 2011-12-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.4.x |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Samori Gorse |
| Maintainers | shinuza |
| Keywords | arithmetic, decimal, float, calculation |

## Links

- npm: https://www.npmjs.com/package/decimal
- Repository: https://github.com/shinuza/decimal-js
- npm.io page: https://npm.io/package/decimal

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

- 0.0.2 (latest) — 2011-12-25

## README

Decimal
======

Simple decimal arithmetic for the browser *and* node.js!


Why?
=======

    Why don’t my numbers, like 0.1 + 0.2 add up to a nice round 0.3,
    and instead I get a weird result like 0.30000000000000004?

    Because internally, computers use a format (binary floating-point)
    that cannot accurately represent a number like 0.1, 0.2 or 0.3 at all.

Source : http://floating-point-gui.de/

I wrote this because I needed to do simple computation in the browser
and I couldn't find a lightweight library to do it.

How to use?
===========


In the browser
--------------

    <script src="lib/decimal.js"></script>

In node
-------

    npm install decimal

then in your program

    var Decimal = require('decimal');


Examples
=======

    >>> 1.1 + 2.2
    3.3000000000000003

    >>> Decimal('1.1').add('2.2').toNumber()
    3.3

    >>> 4.01 * 2.01
    8.060099999999998

    >>> Decimal('4.01').mul('2.01').toNumber()
    8.0601

    >>> Decimal.mul('4.01', '2.01').toNumber()
    8.0601


Can I help?
===========

Of course you can, I suck at math, and this implementation is very naive.
If you are a math Guru and you see something wrong or a
way to simplify things you can send in a pull request.


Methods
=======

Decimal(n)
------------------

Create a new `Decimal` from `n`. `n` can be a string, integer, or
another `Decimal`.

.toString()
------------------

Returns the `Decimal` instance as a string.

.toNumber()
-----------

Turn a `Decimal` into a `Number`.

.add(n)
-------

Return a new `Decimal` containing the instance value plus `n`.

.sub(n)
-------

Return a new `Decimal` containing the instance value minus `n`.

.mul(n)
-------

Return a new `Decimal` containing the instance value multiplied by `n`.

.div(n)
-------

Return a new `Decimal` containing the instance value integrally divided by `n`.

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