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);
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);
Subtract
bn.subtract(0.1);
Multiply
bn.multiply(100);
Divide
bn.divide(2.5);
Power of
bn.pow(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