Skip to content

Commit 1c4baf9

Browse files
author
linzhijun
committed
fix
1 parent 866c119 commit 1c4baf9

11 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎JavaScript/src/Internals/Functions/Financial/Function_DB.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Function_DB extends Function_N {
3333
if (this.z.length > 4) {
3434
const monthArg = this.getNumber(engine, tempParameter, 4);
3535
if (monthArg.IsError) return monthArg;
36-
month = Math.floor(monthArg.NumberValue);
36+
month = monthArg.IntValue;
3737
if (month < 1 || month > 12) return this.parameterError(5);
3838
}
3939

‎JavaScript/src/Internals/Functions/Financial/Function_FV.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class Function_FV extends Function_N {
3636
if (this.z.length > 4) {
3737
const typeArg = this.getNumber(engine, tempParameter, 4);
3838
if (typeArg.IsError) return typeArg;
39-
type = Math.floor(typeArg.NumberValue);
39+
type = typeArg.IntValue;
40+
if (type !== 0 && type !== 1) return this.parameterError(5);
4041
}
4142

4243
if (rate === 0) {

‎JavaScript/src/Internals/Functions/Financial/Function_IPMT.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Function_IPMT extends Function_N {
4040
if (this.z.length > 5) {
4141
const typeArg = this.getNumber(engine, tempParameter, 5);
4242
if (typeArg.IsError) return typeArg;
43-
type = Math.floor(typeArg.NumberValue);
43+
type = typeArg.IntValue;
44+
if (type !== 0 && type !== 1) return this.parameterError(6);
4445
}
4546

4647
const pmt = this.calculatePMT(rate, nper, pv, fv, type);

‎JavaScript/src/Internals/Functions/Financial/Function_MIRR.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ class Function_MIRR extends Function_N {
1717
if (valuesArg.IsError) return valuesArg;
1818
const values = [];
1919
for (const v of valuesArg.ArrayValue) {
20-
values.push(v.NumberValue);
20+
if (v.IsNumber) {
21+
values.push(v.NumberValue);
22+
} else {
23+
const v2 = v.ToNumber(`Function '${this.Name}' parameter 1 is error!`);
24+
if (v2.IsError || v2.IsNone) return v2;
25+
values.push(v2.NumberValue);
26+
}
2127
}
2228

2329
const financeRateArg = this.getNumber(engine, tempParameter, 1);

‎JavaScript/src/Internals/Functions/Financial/Function_NPER.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Function_NPER extends Function_N {
3636
if (this.z.length > 4) {
3737
const typeArg = this.getNumber(engine, tempParameter, 4);
3838
if (typeArg.IsError) return typeArg;
39-
type = Math.floor(typeArg.NumberValue);
39+
type = typeArg.IntValue;
4040
}
4141

4242
if (rate === 0) {

‎JavaScript/src/Internals/Functions/Financial/Function_NPV.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Function_NPV extends Function_N {
1111
}
1212

1313
evaluate(engine, tempParameter) {
14-
if (this.z.length < 2) return this.parameterError(1);
14+
if (this.z.length < 1) return this.parameterError(1);
1515

1616
const rateArg = this.getNumber(engine, tempParameter, 0);
1717
if (rateArg.IsError) return rateArg;

‎JavaScript/src/Internals/Functions/Financial/Function_PMT.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class Function_PMT extends Function_N {
2525
if (pvArg.IsError) return pvArg;
2626
const pv = pvArg.NumberValue;
2727

28+
if (nper === 0) return this.div0Error();
29+
2830
let fv = 0;
2931
if (this.z.length > 3) {
3032
const fvArg = this.getNumber(engine, tempParameter, 3);

‎JavaScript/src/Internals/Functions/Financial/Function_PPMT.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Function_PPMT extends Function_N {
4040
if (this.z.length > 5) {
4141
const typeArg = this.getNumber(engine, tempParameter, 5);
4242
if (typeArg.IsError) return typeArg;
43-
type = Math.floor(typeArg.NumberValue);
43+
type = typeArg.IntValue;
44+
if (type !== 0 && type !== 1) return this.parameterError(6);
4445
}
4546

4647
const pmt = this.calculatePMT(rate, nper, pv, fv, type);

‎JavaScript/src/Internals/Functions/Financial/Function_PV.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class Function_PV extends Function_N {
3636
if (this.z.length > 4) {
3737
const typeArg = this.getNumber(engine, tempParameter, 4);
3838
if (typeArg.IsError) return typeArg;
39-
type = Math.floor(typeArg.NumberValue);
39+
type = typeArg.IntValue;
40+
if (type !== 0 && type !== 1) return this.parameterError(5);
4041
}
4142

4243
if (rate === 0) {

‎JavaScript/src/Internals/Functions/Financial/Function_XIRR.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class Function_XIRR extends Function_N {
2929
dates.push(d.DateValue.ToDateTime(0));
3030
} else if (d.IsText) {
3131
const myDate = MyDate.Parse(d.TextValue);
32-
if (myDate == null) return this.functionError();
32+
if (myDate == null) return this.parameterError(2);
3333
dates.push(myDate.ToDateTime(0));
3434
} else {
35-
return this.functionError();
35+
return this.parameterError(2);
3636
}
3737
}
3838

0 commit comments

Comments
 (0)