[SalesForce] How to format number with comma in apex

I am getting one value from webservice as a string (KM value , say 500000) . I want to display that in an inline vf page as 50,000. How to achieve this in apex controller. I am displaying the valu in a apex datatable as column value.

Please help me out

Eg ; 50000 should be 50,0000 OR 5000000 should be 5,000,000

Best Answer

<apex:outputText value="{0, number, ###,##0}" id="myNumberDisplay" >
    <apex:param value="{!myNumber}"/>
</apex:outputText>

Use apex:outputText with apex:param to format the text. as you are using datatable so it will look like

<apex:column>
   <apex:facet name="header">Owner</apex:facet>
    <apex:outputText value="{0, number, ###,##0}" id="myNumberDisplay" >
        <apex:param value="{!myNumber}"/>
    </apex:outputText>
</apex:column>

In controller you can try this

Decimal rA = 1298763.86;
List<String> args = new String[]{'0','number','###,###,##0.00'};
String s = String.format(rA.format(), args);
System.debug(s);

but still first you need to break the string using '-'

Related Topic