How to Display Decimal Variable as Currency in Visualforce Page

Salesforce has in built functionality to show price with currency sign and formatting for SObject currency fields. But sometimes we need to show price which is not coming from a SObject field. In that case it will show currency sign and formatting. For this we have to tell the apex output tag that the value which we are using is a currency field so that apex output tag will work accordingly.

For rendering any Decimal field as currency field we have to use apex:outputText with value as “{0,number,currency}” . This will tell the output tag the value which we will show in this outputText should be rendered as number currency. Inside this apex:outputText we have to pass apex:param to set the value which we want to show. I used ‘decimalvalue’ which is a decimal field in my controller.

<apex:outputText value="{0, number, currency}">
    <apex:param value="{!decimalValue}" />

Without Using apex:outputText currency format, price will look like : 23.20

With using apex:outputText currency format, price will look like : $23.20

Be the first to comment

Leave a Reply

Your email address will not be published.