lodash-arithmetic
Lodash mixins for arbitrary-precision arithmetic
Why Lo-Dash mixins for arithmetic?
Because of binary floating-point, arithmetic operations in JavaScript may imply rounding issues like:
0.1 + 0.2 = 0.30000000000000004
You will find a complete explanation about floating-point arithmetic at http://floating-point-gui.de/.
Lodash-arithmetic provides simple Lo-Dash mixins for basic arithmetic operations: addition, subtraction, multiplication and division. Even if Lo-Dash 4 natively has the methods .add, .subtract, .multiply and .divide, they do not take in account arbitrary-precision decimal.
Let's see the following examples:
// Without Lo-Dashconsole // false // With Lo-Dash 4 but without the arithmetic mixinsconsole // false // With Lo-Dash and the arithmetic mixinsconsole // true
Install
The easiest way is to install lodash-arithmetic
as dependency
:
npm install lodash-arithmetic --save
Usage
Addition
_; // 0.3
Subtraction
_; // 0.0001
Multiplication
_; // 7
Division
_; // 0.0082
Chaining
value; // 23.00655
License
Code licensed under MIT License.