Hello friends, In today's post we will see a code example that shows you, how you can set decimal place in visualforce page using apex:outputtext tag.

Set decimal places in visualforce pages

In this example decimal places are controlled in visualforce side, nothing to do in apex side.

DecimalPlaces.apxc

 public class DecimalPlaces {
public decimal amount {get;set;}
public DecimalPlaces () {
amount = 50899.7848;
}
}
DecimalPlacesPage.vfp
 <apex:page controller="DecimalPlaces" showHeader="false" sidebar="false">    
<b>1 decimal Place</b><br/>
Amount is :<apex:outputText value="{0, number, ###,###,###,##0.0}"><apex:param value="{!amount}"/></apex:outputText><br/><br/>
<b>2 decimal Places</b><br/>
Amount is :<apex:outputText value="{0, number, ###,###,###,##0.00}"><apex:param value="{!amount}"/></apex:outputText><br/><br/>
<b>3 decimal Places</b><br/>
Amount is :<apex:outputText value="{0, number, ###,###,###,##0.000}"><apex:param value="{!amount}"/></apex:outputText><br/><br/>
<b>4 decimal Places</b><br/>
Amount is :<apex:outputText value="{0, number, ###,###,###,##0.0000}"><apex:param value="{!amount}"/></apex:outputText>
</apex:page>

Output:

 Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.