[SalesForce] outputText number formating with space a thousand separator

How do I format a number in an outputText element so that it uses spaces as a separator between thousands?

What I currently have is an outputText element which formats number using comma as a separator (e.g. 1,000,000.00).

 <apex:outputText value="{0, number, ###,##0.00}">
     <apex:param value="{!item.numberValue}"/>
 </apex:outputText>

However, that doesn't correspond to the user's country locale, where it is usual to have a space as a separator between thousands (1 000 000,00). How do I achieve that? I have tried to add space surrounded by single quotes (which should work according to java MessageFormat) and all sorts of escape characters, but the field ignores the space (resulting in 1000000.00) and takes escapes as literals (with the result looking like: 1000000.00\b).

Any help will be much appreciated.

Best Answer

This is a known behavior which some of us don't like. There seems to be no perfect solution but some workarounds.

The approach is to create the localized string on your own instead of letting salesforce do it.

http://www.interactiveties.com/b_locale_datetime.php#.VGzAacm-O2U Format decimal in <apex:outputText> respecting the user's Locale

You are not alone and may also vote for this idea: https://success.salesforce.com/ideaView?id=08730000000i6AaAAI

EDIT:

  1. Another approach is to use an apex:outputField instead of outputText. There the localization is working as expected and the locale including separators, time and date formats are supported.

  2. Then you could use JavaScript to swap the separators. Easiest way is to use jquery and wrap the outputText with some div to have easy selectors. Firebug is my recommendation to figure out the selectors.

All depends a bit on you skills and what you want to do with the formatted text.