[Libreoffice-commits] core.git: scaddins/source

Winfried Donkers winfrieddonkers at libreoffice.org
Tue Jul 12 12:10:00 UTC 2016


 scaddins/source/analysis/analysishelper.cxx |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 2fd00e59ad6cf55c4fc621724de863947ef6dcf6
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Thu Jul 7 08:16:21 2016 +0200

    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 at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx
index 9b17f04..992abfd 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;
 }


More information about the Libreoffice-commits mailing list