Play Games

Search This Blog

Thursday, April 21, 2016

How to display Rollup Summary Field Value without decimal places in Visualforce Page.

Solution: Use this formatting <apex:outputText value="{0, number, ###,###,###,##0}"><apex:param value="{!a.sum__c}" /></apex:outputText> to display data without decimal values.
Example:
Assume Sum__c is rollup field(sum of its related opportunities Amount) in Account.
Apex Class:
public class RollupWithOutDecimal {
    public List<Account> accountList {get;set;}
    public RollupWithOutDecimal () {
        accountList =[select id,name,sum__C from Account where id=:apexpages.currentpage().getparameters().get('id')];
    }
}
Visualforce Page Code:
<apex:page Controller="RollupWithOutDecimal">
    <apex:form >
        <apex:pageBlock title="My Account" >
                <apex:pageBlockSection columns="4">
                    <apex:pageBlockTable value="{!accountList}" var="a">
                        <apex:column value="{!a.name}"/>
                        <apex:column headerValue="Sum"><apex:outputText value="{0, number, ###,###,###,##0}"><apex:param value="{!a.sum__c}" /></apex:outputText></apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Output: When we run the above vf page with AccountId as id parameter value,then the output will be like this

Note :If you want to restrict number of decimal places after number go through the link given below.
Decimal Places

No comments:

Post a Comment