JSTL Format fmt:parseNumber Tag

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

AttributesDescription
valueSpecifies the string value that has to be parsed.
typeSpecifies that the string has to be parsed as number, currency or percentage.
patternSpecifies the custom pattern to parse the string.
varSpecifies the variable name to which the parse value is to be stored.
scopeThe Scope into which the variable number has to be parsed .
parseLocaleIt is used to set the locale during parsing the number .
integerOnlySpecifies 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:
fmt parseNumber tag output

 

Previous Tutorial : JSTL Format fmt:formatNumber Tag :: Next Tutorial : JSTL Format fmt:timeZone Tag

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*