+ Start a Discussion

formatting percentage and amount fields in VF page

I need to format display probability % for opportunity as 25% instead of 25.0% and amount as $100.20 instead of $100.2.


I could'nt field any functions for formatting in visualforce expression.



What is best way to handle formatting of data?




My code is as below.

<apex:column headerValue="Probability">
<apex:outputLabel value="{!opp.Probability}%" />

<apex:column headerValue="Amount(K)">
<apex:outputLabel value="${!opp.Amount}" />


I was able to display 25 instead of 25.0 by by adding VALUE(TEXT(opp.Probability)) in visualforce expression



<apex:outputLabel value="{!VALUE(TEXT(opp.Probability))}%" />


You can also use outputText, as shown on this page: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm. For example, you can use:


<apex:outputText value="{0,number,0}%">
    <apex:param value="{!opp.Probability}" />

Formulas are shorter, though...