Currency format in Salesforce Visualforce Page

Currency format in Salesforce Visualforce Page

Currency format in Salesforce Visualforce Page can be done using apex:outputText and apex:outputField.

Example:

<apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!a}" />
</apex:outputText>
<apex:outputText value="{0, number, currency}">
    <apex:param value="{!inte}"/>
</apex:outputText>

Note:

Use apex:outputField to consider using User’s locale(currency and date format).

Sample Code:

Visualforce page:

<apex:page controller="SampleVisualforcePageController">  
    <apex:pageBlock >
        <apex:pageBlockSection columns="1">
            <apex:outputText value="${0, number, ###,###,###,##0.00}">
                <apex:param value="{!a}" />
            </apex:outputText>
            <apex:outputText value="${0, number, ###,###,###,##0.00}">
                <apex:param value="{!b}" />
            </apex:outputText>
            <apex:outputText value="${0, number, ###,###,###,##0.00}">
                <apex:param value="{!c}" />
            </apex:outputText>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Apex Class:

public class SampleVisualforcePageController {
    
    public Decimal a { get; set; }
    public Decimal b { get; set; }
    public Decimal c { get; set; }
    
    public SampleVisualforcePageController() {
        
        a = 1800.00;
        b = 200;
        c = 34567.09;
        
    }
    
}

Output:

Sample Code:

Visualforce page:

<apex:page controller="Sample">
<apex:outputLabel value="The value is : "/>
<apex:outputText value="{0, number, currency}">
    <apex:param value="{!inte}"/>
</apex:outputText>
</apex:page>

Apex Controller:

public class Sample { 
    public Decimal inte {get;set;}
    public Sample() {
        inte = 098.23;
    }         
}

Output:

Leave a Reply