zmdms-utils 0.0.69 → 0.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/math.d.ts +1 -1
- package/dist/es/math.js +3 -2
- package/package.json +1 -1
- package/src/math.ts +2 -2
package/dist/es/math.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare function times(num1: numType, num2: numType): number;
|
|
|
14
14
|
/**
|
|
15
15
|
* 除法
|
|
16
16
|
*/
|
|
17
|
-
declare function divide(num1: numType, num2: numType): number;
|
|
17
|
+
declare function divide(num1: numType, num2: numType, precision?: number): number;
|
|
18
18
|
/**
|
|
19
19
|
* 四舍五入保留小数
|
|
20
20
|
*/
|
package/dist/es/math.js
CHANGED
|
@@ -81,7 +81,8 @@ function times(num1, num2) {
|
|
|
81
81
|
/**
|
|
82
82
|
* 除法
|
|
83
83
|
*/
|
|
84
|
-
function divide(num1, num2) {
|
|
84
|
+
function divide(num1, num2, precision) {
|
|
85
|
+
if (precision === void 0) { precision = 5; }
|
|
85
86
|
try {
|
|
86
87
|
var _num1 = num1 == null ? NaN : Number(num1);
|
|
87
88
|
var _num2 = num2 == null ? NaN : Number(num2);
|
|
@@ -90,7 +91,7 @@ function divide(num1, num2) {
|
|
|
90
91
|
if (typeof result === "number") {
|
|
91
92
|
return result;
|
|
92
93
|
}
|
|
93
|
-
Decimal.set({ precision:
|
|
94
|
+
Decimal.set({ precision: precision });
|
|
94
95
|
return new Decimal(_num1).div(_num2).toNumber();
|
|
95
96
|
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
96
97
|
}
|
package/package.json
CHANGED
package/src/math.ts
CHANGED
|
@@ -82,7 +82,7 @@ export function times(num1: numType, num2: numType) {
|
|
|
82
82
|
/**
|
|
83
83
|
* 除法
|
|
84
84
|
*/
|
|
85
|
-
export function divide(num1: numType, num2: numType) {
|
|
85
|
+
export function divide(num1: numType, num2: numType, precision: number = 5) {
|
|
86
86
|
try {
|
|
87
87
|
const _num1 = num1 == null ? NaN : Number(num1);
|
|
88
88
|
const _num2 = num2 == null ? NaN : Number(num2);
|
|
@@ -91,7 +91,7 @@ export function divide(num1: numType, num2: numType) {
|
|
|
91
91
|
if (typeof result === "number") {
|
|
92
92
|
return result;
|
|
93
93
|
}
|
|
94
|
-
Decimal.set({ precision
|
|
94
|
+
Decimal.set({ precision });
|
|
95
95
|
return new Decimal(_num1).div(_num2).toNumber();
|
|
96
96
|
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
97
97
|
} catch (err) {
|