From a7e9d3849c67c8cc977237e59906c9214080142a Mon Sep 17 00:00:00 2001 From: suxiao Date: Tue, 16 Jun 2020 17:07:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7ts=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3node=5Fmodules=E4=B8=ADava=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E4=B8=8D=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- src/index.ts | 4 ++-- test/index.test.ts | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d56ad97..3070564 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "build": "rollup -c", "watch": "rollup -cw", "test": "tsc -p tsconfig.test.json && nyc --reporter=lcov --reporter=text --reporter=json ava && rm -rf .nyc_output", - "test1": "ava", "posttest": "codecov -f coverage/*.json -t 072762c4-c5bc-4393-bcd9-71eac9e7725b", "prepublish": "rm -rf build && tsc && npm run build", "tslint": "tslint './src/**/*.?(ts|tsx)'" @@ -47,7 +46,7 @@ "rollup-plugin-typescript2": "^0.8.4", "rollup-watch": "^4.3.1", "tslint": "^5.8.0", - "typescript": "^2.6.2" + "typescript": "^3.8.3" }, "license": "MIT" } diff --git a/src/index.ts b/src/index.ts index bcff1ff..4e5f509 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ type numType = number | string; * 把错误的数据转正 * strip(0.09999999999999998)=0.1 */ -function strip(num: numType, precision = 12): number { +function strip(num: numType, precision = 15): number { return +parseFloat(Number(num).toPrecision(precision)); } @@ -32,7 +32,7 @@ function float2Fixed(num: numType): number { return Number(num.toString().replace('.', '')); } const dLen = digitLength(num); - return dLen > 0 ? strip(times(num, Math.pow(10, dLen))) : Number(num); + return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num); } /** diff --git a/test/index.test.ts b/test/index.test.ts index 12f5bd9..b5acf76 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -10,7 +10,6 @@ test('NP.strip can eliminate rounding errors', (t) => { test('NP.digitLength can do digitLength operation', (t) => { t.true(NP.digitLength(123.4567890123) === 10); - t.true(NP.digitLength('123.4567890123') === 10); t.true(NP.digitLength(1.23e-5) === 7); t.true(NP.digitLength(1.23e-5) === 7);