Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bigjs-adapter

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigjs-adapter

big.js adapter for linear-arbitrary-precision

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

bigjs-adapter

Build Status Coverage Status Code Climate

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(); // => 20

new Decimal(1).div(3).valueOf(); // => '0.33333333333333333333'

Decimal.setPrecision(5);

new Decimal(1).div(3).valueOf(); // => '0.33333'

Operations

new Decimal(0.1).plus(0.2).valueOf(); // => '0.3'

new Decimal(0.3).minus(0.1).valueOf(); // => '0.2'

new Decimal(0.6).times(3).valueOf(); // => '1.8'

new Decimal(0.3).div(0.2).valueOf(); // => '1.5'

toString, valueOf and toJSON

var decimalThird = new Decimal(1).div(new Decimal(3));

decimalThird.toString() === decimalThird.valueOf() === decimalThird.toJSON(); // => true

Number(decimalThird); // => 1/3

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]);
// => '["0.3333333333333333333333333333333333333333"]'

JSON.parse(stringified, Decimal40.JSONReviver)[0];
// => new Decimal40('0.3333333333333333333333333333333333333333')

See spec.

Keywords

FAQs

Package last updated on 07 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc