[SalesForce] Displaying a % number as 2 decimals places and with a % sign at the end

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)

A read-only display of a label and value for a field on a Salesforce object. An <apex:outputField> component respects the attributes of the associated field, including how it should be displayed to the user. For example, if the specified <apex:outputField> component is a currency field, the appropriate currency symbol is displayed. Likewise, if the <apex:outputField> component is a lookup field or URL, the value of the field is displayed as a link.