The <fmt: parseNumber> tag is used to parse the string representation of numbers, currencies and percentage according to the customized formatting pattern.
Syntax Of <fmt: parseNumber> Tag
<fmt: parseNumber attributes> body content </fmt: parseNumber>
Attributes Of <fmt: parseNumber> Tag
Attributes | Description |
---|---|
value | Specifies the string value that has to be parsed. |
type | Specifies that the string has to be parsed as number, currency or percentage. |
pattern | Specifies the custom pattern to parse the string. |
var | Specifies the variable name to which the parse value is to be stored. |
scope | The Scope into which the variable number has to be parsed . |
parseLocale | It is used to set the locale during parsing the number . |
integerOnly | Specifies that only integer value has to be parsed. |
Example
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>parseNumber</title> </head> <body> <h3>parseNumber Example</h3> <c: set var="Balance" value="15768.50" /> <fmt:parseNumber var="tb" type="number" value="${Balance}" /> <p>Balance: <c:out value="${tb}" /></p> <fmt:parseNumber var="tb" integerOnly="true" type="number" value="${Balance}" /> <p>Balance : <c:out value="${tb}" /></p> </body> </html>
Details of the Code
<fmt:parseNumber var=”tb” integerOnly=”True” type=”number” value=”${Balance}” /> tag is used to parse the number variable and by using integerOnly as true it displays only the integer value in the output.
<c:out> tag is used to display the value in output.
Steps for Execution
- Save this file as example.jsp in your eclipse IDE.
- Now select this jsp file, right mouse click and select Run as ->Run on server
Output
When the execution process is completed successfully we will get the following output:
Previous Tutorial : JSTL Format fmt:formatNumber Tag :: Next Tutorial : JSTL Format fmt:timeZone Tag