+ Start a Discussion
acrozieracrozier 

formatting a dynamic binding for currency

Hello,

 

I have a dynamic binding which generates the sum of a column using a SOQL query.  I want this some to be formatted and displayed for currency.  I can't use the param value of apex:outputext because the value is not populated until run time, so I am getting save errors.  I figure I need to format this in the class and then spit out my formatted value and call that as a dynamic binding, I just can't get it to work.  Can anyone help me figure out how to take this value and format it in this manor? 0, number, ###,###,##0.00

 

public SObject getsumIncentive(){
        SObject sumIncentive;
        sumIncentive = [SELECT SUM(Total__c) sum FROM AIIncentive__c WHERE Job__c =:jobid];
        return sumIncentive;
        }

 

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Hello acrozier,

 

It seems you want to use the sum of Total__c using aggregate qiuery in your vf page.

so for that you need to return the sum in double format.you'll need to convert sum(sObject Row) to sum(Double).


Try this:

 

public Double getsumIncentive(){
        SObject sumIncentive;
        sumIncentive = [SELECT SUM(Total__c) sum FROM AIIncentive__c WHERE Job__c =:jobid]; 
        return Double.valueOf(sumIncentive.get('sum'));
}

In the vf page you can use sumIncentive directly as its in double format.:

 

 

<apex:outputText value="{0, number, ###,###,##0.00}">       
     <apex:param value="{!sumIncentive}" /> 
</apex:outputText>

Hope it helps.    

All Answers

Rahul SharmaRahul Sharma

Hello acrozier,

 

It seems you want to use the sum of Total__c using aggregate qiuery in your vf page.

so for that you need to return the sum in double format.you'll need to convert sum(sObject Row) to sum(Double).


Try this:

 

public Double getsumIncentive(){
        SObject sumIncentive;
        sumIncentive = [SELECT SUM(Total__c) sum FROM AIIncentive__c WHERE Job__c =:jobid]; 
        return Double.valueOf(sumIncentive.get('sum'));
}

In the vf page you can use sumIncentive directly as its in double format.:

 

 

<apex:outputText value="{0, number, ###,###,##0.00}">       
     <apex:param value="{!sumIncentive}" /> 
</apex:outputText>

Hope it helps.    

This was selected as the best answer
acrozieracrozier

thank you, that worked great.