function RoundNumber(b,a){return Math.round(b*Math.pow(10,a))/Math.pow(10,a)}function RoundUpNumber(b,a){return Math.ceil(b*Math.pow(10,a))/Math.pow(10,a)}function CalculateSPPV(b,a){return Math.pow(1+a/100,-b)}function CalculateSPFV(b,a){return Math.pow(1+a/100,b)}function CalculateUSPV(b,a){return(1-CalculateSPPV(b,a))/(a/100)}function CalculateUSFV(b,a){return(CalculateSPFV(b,a)-1)/(a/100)}function GetCompoundPeriods(b,a){return 1*a*1*b/12}function GetPeriodicInterestRate(b,a){return b/(1*a)}
function GetModeValue(b,a){return 1+b*a/100}function CalculateInstallment(b,a,c,d,f,e,g){d-=f;b=GetCompoundPeriods(b,a);a=GetPeriodicInterestRate(c,a);return-((e*CalculateSPPV(b,a)-d)/(GetModeValue(a,g)*CalculateUSPV(b,a)))}function CalculateResidualValue(b,a,c,d,f,e,g){d-=f;b=GetCompoundPeriods(b,a);a=GetPeriodicInterestRate(c,a);return-1*(GetModeValue(a,g)*CalculateUSPV(b,a)*e-d)/CalculateSPPV(b,a)}
function CalculatePresentValue(b,a,c,d,f,e){b=GetCompoundPeriods(b,a);a=GetPeriodicInterestRate(c,a);return GetModeValue(a,e)*CalculateUSPV(b,a)*f+d*CalculateSPPV(b,a)}function CalculateAmount(b,a,c,d,f,e,g){return CalculatePresentValue(b,a,c,d,f,e)+g}function CalculateOneOff(b,a,c,d,f,e,g){return-1*(CalculatePresentValue(b,a,c,d,f,e)-g)}
function CalculateInstallmentRounded(b,a,c,d,f,e,g,h){d=CalculateInstallment(b,a,c,d,f,e,g);h=RoundNumber(d,h);b=-1*CalculateAmount(b,a,c,0,d-h,g,0);return[h,b]}function CalculateResidualValueRounded(b,a,c,d,f,e,g,h,i){b=CalculateResidualValue(b,a,c,d+h,f,e,g);return RoundNumber(b,i)}function CalculateOneOffRounded(b,a,c,d,f,e,g,h,i){b=CalculateOneOff(b,a,c,d,f,e,g+h);return RoundNumber(b,i)}
function CalculateAmountRounded(b,a,c,d,f,e,g,h,i){b=CalculateAmount(b,a,c,d,f,e,g)-h;return RoundNumber(b,i)}function CalculateGrossValue(b,a){return b*(1+a)}function CalculateNetValue(b,a){return b/(1+a)}function CalculateTax(b,a){return b*a}function CalculateRepaymentSchedule(b,a,c,d,f,e,g){c-=f;a=a/12/100;f=[];for(e=0;e<b;e++){var h=1==g&&0==e?0:c*a,i=d-h,c=c-i,h=RoundNumber(h,2),i=RoundNumber(i,2),c=RoundNumber(c,2);f.push([e+1,h,i,c])}return f};
