In JSTL the tag <fmt: format Number> is been preferred for the showing Number formation In different Format. There are some attributes are used in the tag for proper display.
Like Value, type, Pattern, var etc. in Value attribute the required value is been filled as per recommendation the other one we use Type this attribute used to specify that which kind of value will be formatted will it be Number, Currency or Percentage. And in Last we has to use Pattern and var the var attribute used to give a variable name that store the value to be formatted.
<%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>
<html>
<head>
<title><fmt:formatNumber>Tag Example In J.S.P</title>
</head>
<body>
<center><h2>Demo Of Number Format</h2></center>
<c:set var=”format” value=”3400086.789″/>
<p><center><b>Formatted Number (1): <fmt:formatNumber value=”${format}”
type=”currency”/></p></b></center>
<p><center><b>Formatted Number (2): <fmt:formatNumber type=”number”
maxIntegerDigits=”2″ value=”${format}” /></p></b></center>
<p><center><b>Formatted Number (3): <fmt:formatNumber type=”number”
groupingUsed=”true” value=”${format}” /></p></b></center>
<p><b><center>Formatted Number (4): <fmt:formatNumber type=”percent”
maxIntegerDigits=”3″ value=”${format}” /></p></center></b>
<p><b><center>Formatted Number (5): <fmt:formatNumber type=”number”
pattern=”###.###E0″ value=”${format}” /></p></center></b>
<p><center><b>Currency in USA :
<fmt:setLocale value=”en_US”/>
<fmt:formatNumber value=”${format}” type=”currency”/>
</p></b>
</body>
</html>
Here We made a program of <fmt: format Number> first we call the JSTL Library Code in the starting Of program and after then declaring a variable and assures the value we use some required attributes in given codes that will bring the Output as per their phase. Like we use grouping, Decimal place formatting like pattern and currency Mode also. And in the last we closed all the Html tags.