You need to sign in to do that
Don't have an account?
Andy Morton 14
Get and display percentage of two variables from Controller Extension
Hello,
I have an account controller extension as follows which is used by a basic visualforce page to display service statistics for the customer accounts.
I'm wanting to get the percentage of the two variables but having trouble doing so.
I managed to use the following on the VF page:
I've also been informed that its not good practice to do the maths in VF and I should use a wrapper class to output the data to another variable?
My skill with Apex is not great so was wondering if someone could help me get this sorted?
Any help appreciated.
Thanks
Andy
I have an account controller extension as follows which is used by a basic visualforce page to display service statistics for the customer accounts.
public with sharing class CSRCntrlExt2 { Public final Account acct; // Set Public Variables Public Integer tslaok30 {get; private set;} Public Integer tallraised30 {get; private set;} //Get Account Record public CSRCntrlExt2(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); //Get Number of tickets in last 30 days where SLA has been met. tslaok30 = [Select count() FROM Case WHERE AccountId =:acct.Id AND CreatedDate <= LAST_N_DAYS:30 AND Sla_Status__c!='Missed']; //Get Number of tickets raised in last 30 days tallraised30 = [Select count() FROM Case WHERE AccountId =:acct.Id AND CreatedDate <= LAST_N_DAYS:30]; } }
I'm wanting to get the percentage of the two variables but having trouble doing so.
I managed to use the following on the VF page:
<apex:outputtext>{! (tslaok30 / tallraised30)*100}%</apex:outputtext>However, it appends a large number of decmial places to the number, which I don't need (just need whole number, rounded up if possible).
I've also been informed that its not good practice to do the maths in VF and I should use a wrapper class to output the data to another variable?
My skill with Apex is not great so was wondering if someone could help me get this sorted?
Any help appreciated.
Thanks
Andy
<apex:outputText value="{0, number, 0.00}%">
<apex:param value="{!(tslaok30 / tallraised30)*100}" />
</apex:outputText>