diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2016-07-07 08:16:21 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-07-12 12:09:38 +0000 |
commit | 2fd00e59ad6cf55c4fc621724de863947ef6dcf6 (patch) | |
tree | fcd9a742fa97cce65d93fce3ca77655f2d92a663 /scaddins/source/analysis | |
parent | 29089b562ea6d0137cf054d9710b7238e327aa4f (diff) |
tdf#100528 follow up; filter nonsense results.
With unrealistic depreciation rates (>100%), the caluculated amortisation
value can be < 0. Although mathematically correct, financially this is
nonsense. The patch returns 0.0 when the calculated amortisation values
gets < 0.0. (Excel does the same.)
Change-Id: I928bba647429ff6141abfdbd996d4562e31da746
Reviewed-on: https://gerrit.libreoffice.org/26996
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'scaddins/source/analysis')
-rw-r--r-- | scaddins/source/analysis/analysishelper.cxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index 9b17f047b56e..992abfd64554 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -1042,12 +1042,16 @@ double GetAmorlinc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int3 double f0Rate = GetYearFrac( nNullDate, nDate, nFirstPer, nBase ) * fRate * fCost; sal_uInt32 nNumOfFullPeriods = sal_uInt32( ( fCost - fRestVal - f0Rate) / fOneRate ); + double fResult = 0.0; if( nPer == 0 ) - return f0Rate; + fResult = f0Rate; else if( nPer <= nNumOfFullPeriods ) - return fOneRate; + fResult = fOneRate; else if( nPer == nNumOfFullPeriods + 1 ) - return fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate; + fResult = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate; + + if ( fResult > 0.0 ) + return fResult; else return 0.0; } |