arithmetic.js
A small library for mathematical operation in Javascript. only support:
- add (+)
- sub (-)
- mul (*)
- div (/)
Usage
arithmetic.js is easiest to use when installed with npm:
npm install arithmetic.js --save
import
or require
call:
Then you can load the module into your code with a import arithmetic from "arithmetic.js";
// or
var arithmetic = require("arithmetic.js");
Now, there're two methods for you to do the mathematics:
-
smpCal
var smpCal = arithmetic.smpCal; smpCal.add(0.1,0.2) //0.3 smpCal.sub(2,1) //3 smpCal.mul(2,2) //4 smpCal.div(6,3) //2
-
chainCal
chainCal support method chaining, and you can get the result by using function named getValue;
var chainCal = arithmetic.chainCal; // (3 + 0.2 - 1)/4*5 chainCal(3).add(0.2).sub(1).div(4).mul(5).getValue(); // 2.75
Note
arithmetic.js do not support big number;
License
MIT