mugsinc
asked on
Coldfusion PMT(rate,nper,pv,fv) function needed, similar to the one on excel
Coldfusion PMT(rate,nper,pv,fv) function needed, similar to the one on excel
i need a function with all four variable above
i need a function with all four variable above
ASKER
i need it in coldfusion
there is a javascript PMT function provided in another post
<script>
function Pmt(r,np,pv,fv) {
r = r/1200
if (!fv) fv = 0;
pmt=-(r * (fv+Math.pow((1+r),np)*pv) /(-1+Math. pow((1+r), np)));
finalPmt=roundOff(pmt,2);
alert(finalPmt);
}
function roundOff(value, dplaces){
value=value.toString()
if((value.indexOf(".")!=-1 )&&(value. length>(va lue.indexO f(".")+dpl aces))){
three=value.substring(valu e.indexOf( ".")+dplac es+1,value .indexOf(" .")+dplace s+2)
one=value.substring(0,valu e.indexOf( ".")+dplac es)
two=value.substring(value. indexOf(". ")+dplaces ,value.ind exOf(".")+ dplaces+1)
if(parseInt(three)>=5){val ue=one+(pa rseInt(two )+1);value =parseFloa t(value)}
else{value=one+two;value=p arseFloat( value)}
}
return value;
}
</script>
<body onLoad="Pmt(5.75,300,-2000 00);">
https://www.experts-exchange.com/questions/20401797/Urgent-Javascript-PMT-Function.html
<script>
function Pmt(r,np,pv,fv) {
r = r/1200
if (!fv) fv = 0;
pmt=-(r * (fv+Math.pow((1+r),np)*pv)
finalPmt=roundOff(pmt,2);
alert(finalPmt);
}
function roundOff(value, dplaces){
value=value.toString()
if((value.indexOf(".")!=-1
three=value.substring(valu
one=value.substring(0,valu
two=value.substring(value.
if(parseInt(three)>=5){val
else{value=one+two;value=p
}
return value;
}
</script>
<body onLoad="Pmt(5.75,300,-2000
https://www.experts-exchange.com/questions/20401797/Urgent-Javascript-PMT-Function.html
@mugsinc: -- YES that's in CF ONLY, if you are using CF9, then <cfspreadsheet tag users JAVA POI otherwise you can have JAVA POI download and installed separately http://cfsearching.blogspot.com/2008/08/how-to-install-poi-on-coldfusion-8.html
<sfscript>
wb = createObject("java", "org.apache.poi.hssf.recor d.formula. FinanceFun ction").in it();
wb.Pmt(rate, nper, pv, fv, type);
</cfscript>
the above is CF code...
<sfscript>
wb = createObject("java", "org.apache.poi.hssf.recor
wb.Pmt(rate, nper, pv, fv, type);
</cfscript>
the above is CF code...
the above should be read as
<cfscript> <===
wb = createObject("java", "org.apache.poi.hssf.recor d.formula. FinanceFun ction").in it();
wb.Pmt(rate, nper, pv, fv, type);
</cfscript>
<cfscript> <===
wb = createObject("java", "org.apache.poi.hssf.recor
wb.Pmt(rate, nper, pv, fv, type);
</cfscript>
ASKER
i dont want it in java integrated to coldfusion, i am looking for the complete formula done on coldfusion
Have taken the function from ddsh79 and converted to CF
>>
function Pmt(r,np,pv,fv) {
r = r/1200
if (!fv) fv = 0;
pmt=-(r * (fv+Math.pow((1+r),np)*pv) /(-1+Math. pow((1+r), np)));
finalPmt=roundOff(pmt,2);
alert(finalPmt);
}
<<
THE ABOVE FUNCTION IN CF
------
<cffunction name="Pmt" returntype="any" access="public">
<cfargument name="r" required="no" type="any">
<cfargument name="np" required="no" type="any">
<cfargument name="pv" required="no" type="any">
<cfargument name="fv" required="no" type="any" default="0">
<cfset r = r / 1200 />
<cfset pmt = - ( r * (fv + power((1 + r), np) * pv) / (-1 + power((1 + r), np))) />
<cfreturn decimalFormat(pmt) />
</cffunction>
<cffunction name="power" returntype="any" access="public">
<cfargument name="a" type="numeric" required="yes" />
<cfargument name="b" type="numeric" required="yes" />
<cfset apowb = a />
<cfif b GT 1>
<cfloop from="1" to="#b-1#" index="i">
<cfset apowb = apowb * apowb />
</cfloop>
</cfif>
<cfreturn apowb />
</cffunction>
>>
function Pmt(r,np,pv,fv) {
r = r/1200
if (!fv) fv = 0;
pmt=-(r * (fv+Math.pow((1+r),np)*pv)
finalPmt=roundOff(pmt,2);
alert(finalPmt);
}
<<
THE ABOVE FUNCTION IN CF
------
<cffunction name="Pmt" returntype="any" access="public">
<cfargument name="r" required="no" type="any">
<cfargument name="np" required="no" type="any">
<cfargument name="pv" required="no" type="any">
<cfargument name="fv" required="no" type="any" default="0">
<cfset r = r / 1200 />
<cfset pmt = - ( r * (fv + power((1 + r), np) * pv) / (-1 + power((1 + r), np))) />
<cfreturn decimalFormat(pmt) />
</cffunction>
<cffunction name="power" returntype="any" access="public">
<cfargument name="a" type="numeric" required="yes" />
<cfargument name="b" type="numeric" required="yes" />
<cfset apowb = a />
<cfif b GT 1>
<cfloop from="1" to="#b-1#" index="i">
<cfset apowb = apowb * apowb />
</cfloop>
</cfif>
<cfreturn apowb />
</cffunction>
ASKER
i tried the cffunction out in a component, got a value of 0, is the below correct to invoke the function
<cfinvoke component="aFormula.cal" method="Pmt" returnVariable="gpmt"
r="5" np="120" fv="10000" pv="-465286">
<cfdump var="#gpmt#">
<cfinvoke component="aFormula.cal" method="Pmt" returnVariable="gpmt"
r="5" np="120" fv="10000" pv="-465286">
<cfdump var="#gpmt#">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
brilliant, and spot on
http://www.oschina.net/uploads/doc/poi-3.1-FINAL/org/apache/poi/hssf/record/formula/functions/Pmt.html
You can create an object of the class and use it,
wb = createObject("java", "org.apache.poi.hssf.recor
wb.Pmt(rate, nper, pv, fv, type)
rate the loan interest rate.
nper the number of loan repayments.
pv the present value of the future payments (or principle).
fv the future value (default zero) surplus cash at the end of the loan lifetime.
type whether payments are due at the beginning(1) or end(0 - default) of each payment period.