bigjs-adapter
big.js adapter for
linear-arbitrary-precision
Install
npm i bigjs-adapter
Usage
Factory and configuration
var decimalFactory = require('linear-arbitrary-precision');
var adapter = require('bigjs-adapter');
var Decimal = decimalFactory(adapter);
Decimal.getPrecision();
new Decimal(1).div(3).valueOf();
Decimal.setPrecision(5);
new Decimal(1).div(3).valueOf();
Operations
new Decimal(0.1).plus(0.2).valueOf();
new Decimal(0.3).minus(0.1).valueOf();
new Decimal(0.6).times(3).valueOf();
new Decimal(0.3).div(0.2).valueOf();
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(3);
var stringified = JSON.stringify([decimalThird]);
JSON.parse(stringified, Decimal40.JSONReviver)[0];
See spec.