Ad Code

Responsive Advertisement

PMT Method in Salesforce/ PMT Function in Salesforce

We sometime face problem how to conclude this PMT Excel function in Salesforce.



Following is the Apex Class


public class PMTFunctionCntrl {

    public PageReference calculate() {
    
     try{
     
       if(inputRate==null || inputAmount==null || inputperiod==null)
       {
         return null;
       }
       double amount = double.valueof(inputAmount);
       double Rate = double.valueof(inputRate);
       double period = double.valueof(inputperiod);
       double result1= math.pow(1+(Rate/100),period);
       double xResult1= (result1*(Rate/100));
       double result2= (math.pow((1+(Rate/100)),period)-1);
       double finalResult1 = (amount*(xResult1/result2));
       amtResult=finalResult1 ;
     
     }catch(exception ex){
       return null;
     }  
        return null;
    }
    
    public double inputAmount{get;set;}
    public double inputperiod{get;set;}
    public double inputRate{get;set;}
    public double amtResult{get;set;}

}


Following is the visualforce Page

<apex:page controller="PMTFunctionCntrl" docType="HTML-5.0">
<apex:form id="changeStatusForm">
        <apex:pageBlock >
        <apex:pageMessages />
        <apex:pageBlockButtons >
            <apex:commandButton value="Calculate" action="{!calculate}" reRender="result"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="2">
            
                
                <apex:outputText value="Rate"></apex:outputText>
                <apex:input value="{!inputRate}" id="theTextInputRate" />
                <apex:outputText value="Period"></apex:outputText>
                <apex:input value="{!inputperiod}" id="theTextInputPrd" type="number"/>
                <apex:outputText value="Amount" ></apex:outputText>
                <apex:input value="{!inputAmount}" id="theTextInputAmt" type="number"/>
                
            
        </apex:pageBlockSection> 
        <apex:pageBlockSection columns="2" id="result">
                <apex:outputText value="Amortization Amount"></apex:outputText>
                <apex:outputText value="{!amtResult}"></apex:outputText>
        </apex:pageBlockSection> 
        </apex:pageBlock>
    </apex:form>


Reactions

Post a Comment

1 Comments

  1. Hi Amul,

    Thanks for sharing this, but it doesn't give accurate result.

    If we pass Amt=143974,Period=18,Rate=1.5
    Expected = 9197.20
    Output by above calculation = 9186.42

    Please help.

    Thanks!

    ReplyDelete