function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pelika Gupta 2pelika Gupta 2 

Formatting numbers in Apex:outputtext to include space between numbers

Below is the code used to display Amount where thousand separator is comma : 
<apex:outputText value="{0, number, ###,###,###,###}"> <apex:param value="{!family.totalSalesPlanAmount}"/> </apex:outputText>
Original number: 12123
RESULT after formatting: 12,123

But i want to display thousand seperator as space. Eg: 12 123 (french format)
i have tried below codes but not able to achieve success: 
<apex:outputText escape="false" value="{0, number, ###&nbsp;###&nbsp;###&nbsp;###}">
it gives me result: 12123&16

CAn you please help me to format the number in french format where thousand separator is space
LBKLBK
Unfortunately, this is not possible with apex:outputText yet.

Can you not use apex:outputField instead of apex:outputText?

If your field is currency type, formatting is automatically taken care of by apex:outputField, based on the user's currency setting.
pelika Gupta 2pelika Gupta 2
The field is not currency field. Also, the value displayed here is calculated dynamically at that time.. but outputfield donot support dynamic binding. 
LBKLBK
Oh OK.

This is a tricky situation.

I guess you need to format the text in APEX code before displaying it in the VF page.

Even though it is lot of custom coding, I cannot think of another way.
 
LBKLBK
Try this method to format your amount into the Currency and Delimter you want.
 
public class clsCurrencyFormat {
    public static String FormatCurrency(String sValue, String sCurrencySymbol, String sDelimiter){
        String sAfterDecimal = '';
        String sNewValue = '';
        
        if(sValue.contains('.')){
            String[] arrValues = sValue.split('\\.');
            sValue = arrValues[0];
            sAfterDecimal = arrValues[1];
        }
        while(sValue.length() > 0){
            String sInterimValue = '';
            if(sValue.length() <= 3){
                sInterimValue = sValue;
                sValue = '';
            }
            else{
                sInterimValue = sValue.right(3);
                sValue = sValue.left(sValue.length() - 3);
            }
            if(String.isEmpty(sNewValue)){
                sNewValue = sInterimValue;
            }
            else{
                sNewValue = sInterimValue + sDelimiter + sNewValue;
            }
        }
        
        if(!String.isEmpty(sAfterDecimal)){
            sNewValue = sNewValue + '.' + sAfterDecimal;
        }
        return sCurrencySymbol + sNewValue;
    }
}
Let me know if this helps.