calculate-asmd
The precise addition, subtraction, multiplication and division of JavaScript avoids the error of floating point calculation.
Production
0.2 + 0.4 = 0.6 ?
Install
yarn
yarn add calculate-asmd
npm
npm install calculate-asmd --save
umd
<script src="https://unpkg.com/calculate-asmd@2.4.4/dist/index.umd.js"></script>
OR
<script src="https://unpkg.com/calculate-asmd@2.4.4/dist/index.umd.min.js"></script>
Tips: You can find the library on window.CalculateAsmd.
Usage
import { add, sub, mul, div } from 'calculate-asmd'
const addNum = add(0.2, 0.4);
console.log("add(0.2, 0.4): ", addNum); //add(0.2, 0.4): 0.6
const addNegative = add(0.2, -0.4);
console.log("add(0.2, -0.4): ", addNegative); //add(0.2, -0.4): -0.2
const subNum = sub(0.2, 0.4);
console.log("sub(0.2, 0.4): ", subNum); //sub(0.2, 0.4): -0.2
const subNegative = sub(0.2, -0.4);
console.log("sub(0.2, -0.4): ", subNegative); //sub(0.2, -0.4): 0.6
const mulNum = mul(0.57, 100);
console.log("mul(0.57, 100): ", mulNum); //mul(0.57, 100): 57
const mulNegativ = mul(-0.57, 100);
console.log("mul(-0.57, 100): ", mulNegativ); //mul(-0.57, 100): -57
const divNum = div(0.57, 100);
console.log("div(0.57, 100): ", divNum); //div(0.57, 100): 0.0057
const divNegative = div(-0.57, 100);
console.log("div(-0.57, 100): ", divNegative); //div(-0.57, 100): -0.0057
asmd(arg1,arg2)
arg1
: Default 0, type number/string
arg2
: Default 0, type number/string
Tips: If arg is NaN, it will return NaN directly. If arg is null/undefined/"", arg will be treated as 0
div(arg1,arg2)
arg2
: If arg2 is 0, it will return Infinity.
Expand
import { scaleNum } from 'calculate-asmd'
scaleNum(0.57, 2) // 57
scaleNum(0.57, -2) // 0.0057
scaleNum(0.57, 0) // 0.57
Test
Test Document
LICENSE
MIT License