Play Games

Search This Blog

Tuesday, December 8, 2015

How to display only 2 decimal values of a number in visualforce page (Restricting number of decimal values)

Apex Class:
Public class RestrictDecimalPlaces {
    public decimal weight {get;set;}
    public RestrictDecimalPlaces () {
        weight = 50.6789;
    }

}
Visualforce Page:
<apex:page controller="RestrictDecimalPlaces">
Weight is :<apex:outputText value="{0, number, ###,###,###,##0.0}"><apex:param value="{!weight}" /></apex:outputText>(Restricting to 1 decimals)<br/><br/>
Weight is :<apex:outputText value="{0, number, ###,###,###,##0.00}"><apex:param value="{!weight}" /></apex:outputText>(Restricting to 2 decimals)<br/><br/>
Weight is :<apex:outputText value="{0, number, ###,###,###,##0.000}"><apex:param value="{!weight}" /></apex:outputText>(Restricting to 3 decimals) <br/><br/>
Weight is :<apex:outputText value="{0, number, ###,###,###,##0.0000}"><apex:param value="{!weight}" /></apex:outputText>(Restricting to 4 decimals)

</apex:page>
Output:

No comments:

Post a Comment