Lodash mixins for arbitrary-precision arithmetic
Why Lo-Dash mixins for arithmetic?
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
The easiest way is to install
npm install lodash-arithmetic --save
_; // 0.3
_; // 0.0001
_; // 7
_; // 0.0082
value; // 23.00655
Code licensed under MIT License.