+ Start a Discussion

Perform Calculation on Vf page using parameters from controller

   I want to perform a simple calculation on my Vf page. I have an integer  countCompleted and a decimal auditsToBeMade variable on the controller side.
public Integer getcountCompleted(){
        Integer countCompleted = [select COUNT() from Financial_Audit_Plan__c where YTD_Completed_Audits__c = 1 AND ((DM1__c = :userInfo.getUserID())
                                       OR (DM2__c = :userInfo.getUserID()) OR (DM3__c = :userInfo.getUserID()) OR (DM4__c = :userInfo.getUserID())) AND Calendar_year(Planification_Date__c) = :System.today().year()];
        System.debug('Total is '+countCompleted);
        return countCompleted;
public Decimal getauditsToBeMade(){
        if(financial1!=null && total_size!=0)                                                                                
        auditsToBeMade = financial1[0].Total_Planned_Audits__c;
        return auditsToBeMade;
I just want to dispaly something like this. ({!countCompleted}/{!auditsToBeMade})*100%  on the page.  I tried by creating a new variable on the controller and performing calculation there and then displaying that variable on the page.: 
public Decimal getpercentAudit(){
            Decimal percentAudit = (getcountCompleted()/getauditsToBeMade())*100;
            System.debug('Percent is '+percentAudit);
            return percentAudit.setScale(2, RoundingMode.HALF_UP);
            return null;
But I get an exception whenever getauditsToBeMade() method doent return any value, how can i prevent this error? Please advice.
Thank you
Surya Teja 44Surya Teja 44
I think you need to call getpercentAudit() from your constructor and assign the value it returns to a get;set; variable. Use that on your page. Give it a try and let me know if it works.
Hi Thank you for your reply. but I am not sure if I understand wht you are saying. Can you please elaborate or show some example?