I want to display a percentage number in my visual force page and I want it to have 2 decimal places and a %
sign following the number (eg. 2.50%).
I have a custom field of type Percent
and I called it Rate__c
in my custom object app__c
.
I current have this line of code in my VF page please help me confirm if it is doing the right thing as I have asked?
<apex:outputText value="{0, number, ##.##}%"><apex:param value="{!app.Rate__c}"/></apex:outputText>
I have looked up and some other sources suggest it to be written like this:
<apexutputText value="{0, number, 000,000.00}">
I am also not quite understand what is the different between using the "#" vs using the 0
when formatting the number.
Thanks
Best Answer
In this case, it'd be easier to just use
<apex:outputField>
. It automatically applies formatting based on the field metadata (i.e. Type = percentage and decimals = 2).This behavior is documented. From the documentation on
<apex:outputField>
(emphasis mine)