diff --git a/Excel/.unit-tests/FormulaTests.js b/Excel/.unit-tests/FormulaTests.js index b3d2834c09abe5d4609da30c8ce8eb0fa0e294bd..16b4af191f2a5c43fdb5aef73bd9219a9f1ba84a 100644 --- a/Excel/.unit-tests/FormulaTests.js +++ b/Excel/.unit-tests/FormulaTests.js @@ -4465,11 +4465,11 @@ function db( cost, salvage, life, period, month ){ - if( cost == 0 || salvage == 0 ){ - return 0; + if ( salvage >= cost ) { + return this.value = new cNumber( 0 ); } - if ( month < 1 || month > 12 || salvage <= 0 || life <= 0 || period < 0 || life + 1 < period || cost < 0 || cost < salvage ) { + if ( month < 1 || month > 12 || salvage < 0 || life <= 0 || period < 0 || life + 1 < period || cost < 0 ) { return "#NUM!"; } @@ -5617,4 +5617,44 @@ }) + test( "Test: \"ERF\"", function () { + + oParser = new parserFormula( "ERF(1.234,4.5432)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.08096058291050978 ); + + oParser = new parserFormula( "ERF(1)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.8427007929497149 ); + + oParser = new parserFormula( "ERF(0,1.345)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.9428441710878559 ); + + oParser = new parserFormula( "ERF(1.234)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.9190394169576684 ); + + }) + + test( "Test: \"ERFC\"", function () { + + oParser = new parserFormula( "ERFC(1.234)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.08096058304233157 ); + + oParser = new parserFormula( "ERFC(1)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 0.15729920705028513 ); + + oParser = new parserFormula( "ERFC(0)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), 1 ); + + oParser = new parserFormula( "ERFC(-1)", "A2", ws ); + ok( oParser.parse() ); + strictEqual( oParser.calculate().getValue(), "#NUM!" ); + + }) + } ); diff --git a/Excel/model/FormulaObjects/financialFunctions.js b/Excel/model/FormulaObjects/financialFunctions.js index e35d1c2e222415e148b2deeb57828f71952df282..a0684c53530104a5380c677b39e2661d5f4b61c3 100644 --- a/Excel/model/FormulaObjects/financialFunctions.js +++ b/Excel/model/FormulaObjects/financialFunctions.js @@ -1906,15 +1906,16 @@ cDB.prototype.Calculate = function ( arg ) { salvage = salvage.getValue(); life = life.getValue(); period = period.getValue(); - month = month.getValue(); + month = Math.floor(month.getValue()); - if( cost == 0 || salvage == 0 ){ + if ( salvage >= cost ) { return this.value = new cNumber( 0 ); } - if ( month < 1 || month > 12 || salvage <= 0 || life <= 0 || period < 0 || life + 1 < period || cost < 0 || cost < salvage ) { + if ( month < 1 || month > 12 || salvage < 0 || life < 0 || period < 0 || life + 1 < period || cost < 0 ) { return this.value = new cError( cErrorType.not_numeric ); } + var rate = 1 - Math.pow( salvage / cost, 1 / life ); rate = Math.floor( (rate * 1000) + 0.5 ) / 1000; var firstRate = cost * rate * month / 12;