@rinxun/numeric-calculator 1.0.6-beta.1 → 1.0.7-alpha.1
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/index.d.ts +12 -0
- package/index.js +22 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -81,6 +81,12 @@ declare class Calculator {
|
|
|
81
81
|
* @param {number} num2 operand 2
|
|
82
82
|
*/
|
|
83
83
|
private processPlus;
|
|
84
|
+
/**
|
|
85
|
+
* core processor for round
|
|
86
|
+
* @param {number} num numeric
|
|
87
|
+
* @param {number} fractionDigits default 2
|
|
88
|
+
*/
|
|
89
|
+
private processRound;
|
|
84
90
|
/**
|
|
85
91
|
* core processor for times
|
|
86
92
|
* @param {IOperand[]} operands operands
|
|
@@ -125,5 +131,11 @@ declare class Calculator {
|
|
|
125
131
|
* @param {Array<IOperand>} operands operands
|
|
126
132
|
*/
|
|
127
133
|
divide(...operands: Array<IOperand>): this;
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @param {number} fractionDigits default to 2, should be in the range 0 - 20
|
|
137
|
+
* @returns {number} rounded result
|
|
138
|
+
*/
|
|
139
|
+
round(fractionDigits?: number): number;
|
|
128
140
|
}
|
|
129
141
|
export default Calculator;
|
package/index.js
CHANGED
|
@@ -186,6 +186,17 @@ var Calculator = /** @class */ (function () {
|
|
|
186
186
|
this.checkBoundary(amplifyingResult);
|
|
187
187
|
return amplifyingResult / magnification;
|
|
188
188
|
};
|
|
189
|
+
/**
|
|
190
|
+
* core processor for round
|
|
191
|
+
* @param {number} num numeric
|
|
192
|
+
* @param {number} fractionDigits default 2
|
|
193
|
+
*/
|
|
194
|
+
Calculator.prototype.processRound = function (num, fractionDigits) {
|
|
195
|
+
var magnification = Math.pow(10, fractionDigits || this._fractionDigits || 2);
|
|
196
|
+
var amplifyingResult = this.processTimes(num, magnification);
|
|
197
|
+
this.checkBoundary(amplifyingResult);
|
|
198
|
+
return this.processDivide(Math.round(num), magnification);
|
|
199
|
+
};
|
|
189
200
|
/**
|
|
190
201
|
* core processor for times
|
|
191
202
|
* @param {IOperand[]} operands operands
|
|
@@ -309,6 +320,17 @@ var Calculator = /** @class */ (function () {
|
|
|
309
320
|
this.calculate(operands, "divide");
|
|
310
321
|
return this;
|
|
311
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
*
|
|
325
|
+
* @param {number} fractionDigits default to 2, should be in the range 0 - 20
|
|
326
|
+
* @returns {number} rounded result
|
|
327
|
+
*/
|
|
328
|
+
Calculator.prototype.round = function (fractionDigits) {
|
|
329
|
+
var magnification = Math.pow(10, fractionDigits || this._fractionDigits || 2);
|
|
330
|
+
var amplifyingResult = this.processTimes(this._VALUE || 0, magnification);
|
|
331
|
+
this.checkBoundary(amplifyingResult);
|
|
332
|
+
return this.processDivide(Math.round(amplifyingResult), magnification);
|
|
333
|
+
};
|
|
312
334
|
return Calculator;
|
|
313
335
|
}());
|
|
314
336
|
exports.default = Calculator;
|
package/package.json
CHANGED