Commit e0daf854 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

fixed: Bug 25055 - Ошибка при расчете формулы DB если аргументы Cost/Salvage пустые

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57448 954022d7-b5bf-4e40-9824-e11837661b57
parent be4e73b8
......@@ -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!" );
})
} );
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment