# Convert Number Format

This tutorial discusses about converting a String value in the page to the Number object. When converting, minimum and maximum number of digits in the integer and fractional part can be specified to be formatted.

Tutorials

# Convert Number Format

This tutorial discusses about converting a String value in the page to the Number object. When converting,  minimum and maximum number of digits in the integer and fractional part can be specified to be formatted. For this we can use convertNumber tag which provides these functionalities. It's attribute "type" specifies the type of formatting like number, currency, percentage.

Code description :

cnf.jsp : In this code we have used convertNumber tag. minFractionDigits specifies minimum no. of digits that is to be formatted. In the same way maxFractionDigits is used to specify maximum no. of digits to be formatted. currencySymbol attribute is used to specify the currency symbol that will be applied when formatting currency values.

 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> JSF Login Example By Using Component Binding

In this program minFractionDigits is set to "3" and maxFractionDigits to "5" so if we pass less than 3 digits in fractional part then it takes it upto 3 digits and if we pass more than 5 digits then it takes the number upto 5 digits in the fractional part. If the currencySymbol attribute is set to "\$" then the value must start with that currency symbol.

If we put the values below :

then error message will come indicating the conversion error because "\$" sign has not been supplied in the second input text box.

If we put more than 5 digits :

then it round it off and presents with 5 digits because we have already specified maxFractionDigits to "5".

# Convert Number Format

Related Tutorials

Discuss: Convert Number Format