Find your content:

Search form

You are here

Formatting number values on Visualforce page


I am wondering if it is possible to dynamically format input numbers in Visualforce components when rendering as HTML. I am able to successfully accomplish this when rendering as output tags doing the following:

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

Which yields a value of 123,456 provided myNumber is an Integer of 123456. In an ideal world, this would work in inputText as well (and there are ways to accomplish this via javascript), but I am curious if there is anything "out of the box" with Salesforce.

UPDATE: Modified original question after noticing a syntax error.

Attribution to: Michael Welburn

Possible Suggestion/Solution #1

I don't think there is any built-in SF function that will achieve exactly what you want. But you might be able to get close by mixing in a bit of javascript. The below is something I have scratched out here and isnt complete but should go the right way.

I think you could use a combination of a hidden inputText field to hold the value and an output field for displaying. When the outputText is clicked on it is hidden by a js function and the inputText is shown. When the input text is changed a js function hides the input and an actionSupport fires to update the outputText display. The action support may need to also update the controller with the new value but I havent added that at the moment.

<apex:inputField value="{!Object.myNumber}" id="myNumberInput"onclick="hideInput('myNumber')">
    <apex:actionSupport event="onchange" reRender="myNumberDisplay"/>

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

Attribution to: Jon Hazan
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content