New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

decimath

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decimath

Small, Simple library for Precise Decimal Calculations

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

DeciMath

A small JavaScript library for doing precise floating point maths

Sure, there are many maths libraries to tickle your fancy, but sometimes you just need proper floating point maths and nothing more, that's why this library exists.

Install

Node/React

npm install decimath
yarn add decimath

Browser

Just copy and link to the file or include it in your scripts.

Usage

Node Only:

import BigNumber from 'decimath';

You'll need a BigNumber to make use of this. To make a new Big Number Use the following:

let bn = BigNumber(0.1); // initial value

Operations

All operations support a value as either a BigNumber or any other numeric type that can be converted to a BigNumber.

All operations except Power Of accept decimal values.

All operations return this to allow chaining. To Get the value, end the chain with .valueOf()

Add

bn.add(0.2); // adds 0.2 to our initial value

Subtract

bn.subtract(0.1); // Takes 0.1 from our value

Multiply

bn.multiply(100); // Multiplies value by 100

Divide

bn.divide(2.5); // Divides our value by 2.5

Power of

bn.pow(30); // bn to the power of 30

Using calculated values outside of the library

Use .valueOf() to get the JS decimal version of the number

Used By

Live Preview

https://repl.it/@Snaddyvitch_Dis/Decimath-Testing

Keywords

FAQs

Package last updated on 09 Feb 2021

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