JavaTpoint | Core Java Tutorial | Java Tutorial Point

RSS Feed URL: http://www.javatutorialpoint.com/feeds/posts/default
Category: Java | Total Views: 1211

Latest entries from this feed

JSTL fmt:parseNumber Formatting Tag

Posted on 21 July 2017 | 4:59 pm by Nitish Chauhan

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:




Related products