JSTL fmt:parseNumber Formatting Tag

The JSTL <fmt:parseNumber> Formatting Tag is used for parsing the numbers, currencies and percentages.

Syntax:

<fmt:parseNumber value=”val” otherattributes />

fmt:parseNumber tag attributes:

Attribute Description Required
value Numeric value to read or parse. No
type NUMBER, CURRENCY, PERCENT. No
parseLocale Locale to use when parsing the number. No
integerOnly Whether to parse to an integer (true) or floating point number (false). No
pattern It specify the custom parsing pattern. No
timeZone It specify the time zone of the displayed date. No
var It specify the name of the variable to store the parsed number. No
scope It specify the scope of the variable to store the parsed number. No

Example:

test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 
<html>
  <head>
 	<title>fmt:parseNumber JSTL formatting tag example</title>
  </head>
  <body>
    <c:set var="number" value="324123.23234"/>
    Number after parsing by setting type attribute: <br/>
    <fmt:parseNumber  var="num" value="${number}" type="number"/> 
    <c:out value="${num}"/><br/>
    Number after parsing by setting integerOnly attribute to true: <br/>
    <fmt:parseNumber  var="num" value="${number}" integerOnly="true"/> 
    <c:out value="${num}"/>
  </body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 44   Download this example.   Next Topic: JSTL fmt:formatDate Formatting Tag with example. Previous Topic: JSTL fmt:formatNumber Formatting Tag with example.

 

Please follow and like us:
Content Protection by DMCA.com