calculate-asmd
Advanced tools
Comparing version 2.0.0 to 2.2.2
{ | ||
"name": "calculate-asmd", | ||
"version": "2.0.0", | ||
"description": "加减乘除四则运算(calculate/arithmetic)", | ||
"main": "index.js", | ||
"author": "sanshuiwang", | ||
"license": "MIT", | ||
"version": "2.2.2", | ||
"description": "calculate/arithmetic", | ||
"scripts": { | ||
"test": "node ./test/test.js" | ||
"start": "umi-lib doc dev", | ||
"doc": "umi-lib doc build && cpx docs/404.html .docz/dist/ && umi-lib doc deploy", | ||
"build": "umi-lib build", | ||
"prepare": "yarn run build", | ||
"test": "yarn run build && mocha" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"jsnext:main": "dist/index.esm.js", | ||
"typings": "dist/index.d.ts", | ||
"sideEffects": false, | ||
"repository": { | ||
@@ -15,10 +21,29 @@ "type": "git", | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"keywords": [ | ||
"calculate", | ||
"arithmetic" | ||
"axios", | ||
"last" | ||
], | ||
"author": "WangYang", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/sanshuiwang/calculate-asmd/issues" | ||
}, | ||
"homepage": "https://github.com/sanshuiwang/calculate-asmd#readme" | ||
"homepage": "https://github.com/sanshuiwang/calculate-asmd#readme", | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"cpx": "^1.5.0", | ||
"docz-plugin-splash": "^1.0.1", | ||
"eslint": "^5.15.3", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"mocha": "^6.0.2", | ||
"nock": "^10.0.6", | ||
"typescript": "^3.3.4000", | ||
"umi-library": "^1.4.1" | ||
}, | ||
"peerDependencies": {} | ||
} |
# calculate-asmd | ||
<h3>javascript 精确四则运算</h3> | ||
<h3>JavaScript Arithmetic</h3> | ||
> 生产原因 | ||
> Production | ||
1. 浮点数值的最高进度是 17 位小数,但在进行运算的时候其精确度却远远不如整数;整数在进行运算的时候都会转成 10 进制。 | ||
2. Java 和 JavaScript 中计算小数运算时,都会先将十进制的小数换算到对应的二进制,一部分小数并不能完整的换算为二进制,这里就出现了第一次的误差。 | ||
3. 待小数都换算为二进制后,再进行二进制间的运算,得到二进制结果。然后再将二进制结果换算为十进制,这里通常会出现第二次的误差。 | ||
[0.2 + 0.4 = 0.6 ?](https://github.com/sanshuiwang/Blog/issues/9) | ||
> 使用 | ||
> Usage | ||
<h4>安装</h4> | ||
<h4>Install</h4> | ||
@@ -26,25 +24,38 @@ `yarn add calculate-asmd --dev` | ||
/** 加法 */ | ||
const addNum = add(9.9, 0.2); | ||
console.log("add: ", addNum); | ||
const addNum = add(0.2, 0.4); | ||
console.log("add(0.2, 0.4): ", addNum); | ||
const addNegative = add(0.2, -0.4); | ||
console.log("add(0.2, -0.4): ", addNegative); | ||
/** | ||
*add(0.2, 0.4): 0.6 | ||
*add(0.2, -0.4): -0.2 | ||
*/ | ||
/** 减法 */ | ||
const subNum = sub(9.9, 0.2); | ||
console.log("sub: ", subNum); | ||
const subNum = sub(0.2, 0.4); | ||
console.log("sub(0.2, 0.4): ", subNum); | ||
const subNegative = sub(0.2, -0.4); | ||
console.log("sub(0.2, -0.4): ", subNegative); | ||
/** | ||
*sub(0.2, 0.4): -0.2 | ||
*sub(0.2, -0.4): 0.6 | ||
*/ | ||
/** 乘法 */ | ||
const mulNum = mul(9.9, 0.2); | ||
console.log("mul: ", mulNum); | ||
const mulNum = mul(0.57, 100); | ||
console.log("mul(0.57, 100): ", mulNum); | ||
const mulNegativ = mul(-0.57, 100); | ||
console.log("mul(-0.57, 100): ", mulNegativ); | ||
/** | ||
*mul(0.57, 100): 57 | ||
*mul(-0.57, 100): -57 | ||
*/ | ||
/** 除法 */ | ||
const divNum = div(9.9, 0.2); | ||
console.log("div: ", divNum); | ||
const divNum = div(0.57, 100); | ||
console.log("div(0.57, 100): ", divNum); | ||
const divNegative = div(-0.57, 100); | ||
console.log("div(-0.57, 100): ", divNegative); | ||
/** | ||
*div(0.57, 100): 0.0057 | ||
*div(-0.57, 100): -0.0057 | ||
*/ | ||
``` | ||
> 参考 | ||
[精确四则运算](https://blog.csdn.net/u010004317/article/details/79009172) | ||
[js 小数运算出现多位小数如何解决 | ||
](http://www.cnblogs.com/zdz8207/p/js-number-tofixed.html) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16801
6
483
61
10
1