arbitrary-precision
![Code Climate](https://codeclimate.com/github/javiercejudo/arbitrary-precision/badges/gpa.svg)
Abstraction for decimal functionality in
big.js,
bignumber.js,
decimal.js
and others via adapters.
Install
npm i arbitrary-precision
Adapters
See up to date list.
Usage
var decimalFactory = require('arbitrary-precision');
var adapter = require('floating-adapter');
var Decimal = decimalFactory(adapter);
Operations
new Decimal('0.1').plus(new Decimal('0.2')).valueOf();
new Decimal('0.3').minus(new Decimal('0.1')).valueOf();
new Decimal('0.6').times(new Decimal('3')).valueOf();
new Decimal('0.3').div(new Decimal('0.2')).valueOf();
new Decimal('2').pow(new Decimal('3')).valueOf();
new Decimal('9').sqrt().valueOf();
new Decimal('2').equals(new Decimal('2'));
new Decimal('2').equals(new Decimal('3'));
new Decimal('2').lt(new Decimal('3'));
new Decimal('2').cmp(new Decimal('3'));
toString, valueOf and toJSON
var decimalThird = new Decimal('1').div(new Decimal('3'));
decimalThird.toString() === decimalThird.valueOf() === decimalThird.toJSON();
Number(decimalThird);
JSON.stringify and JSON.parse with reviver
var Decimal40 = decimalFactory(adapter);
Decimal40.setPrecision(40);
var decimalThird = new Decimal40('1').div(new Decimal('3'));
var stringified = JSON.stringify(decimalThird);
JSON.parse(stringified, Decimal40.reviver);
See spec.