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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!