JSTL fmt:parseNumber Formatting Tag

The JSTL Formatting Tag is used for parsing the numbers, currencies and percentages.
Syntax:

fmt:parseNumber tag attributes:

AttributeDescriptionRequired
valueNumeric value to read or parse.No
typeNUMBER, CURRENCY, PERCENT.No
parseLocaleLocale to use when parsing the number.No
integerOnlyWhether to parse to an integer (true) or floating point number (false).No
patternIt specify the custom parsing pattern.No
timeZoneIt specify the time zone of the displayed date.No
varIt specify the name of the variable to store the parsed number.No
scopeIt 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:


No comments: