CodesJava

Easy learning with example program codes

JSTL fmt:formatNumber Formatting Tag

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

Syntax:

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

fmt:formatNumber tag attributes:

AttributeDescriptionRequired
valueIt specify the numeric value to display.Yes
typeNUMBER, CURRENCY, PERCENTNo
patternIt specify a custom formatting pattern for the output..No
currencyCodeCurrency code (for type=”currency”).No
currencySymbolCurrency symbol (for type=”currency”).No
groupingUsedIt specify whether to group numbers (TRUE or FALSE).No
maxIntegerDigitsIt specify the maximum number of integer digits to print.No
minIntegerDigitsIt specify the minimum number of integer digits to print.No
maxFractionDigitsIt specify the maximum number of fractional digits to print.No
minFractionDigitsIt specify the minimum number of fractional digits to print.No
varIt specify the name of the variable to store the formatted number.No
scopeIt specify the scope of the variable to store the formatted numberNo

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:formatNumber JSTL formatting tag example</title>
  </head>
  <body>
    <c:set var="num" value="324123.23234"/>
    Number after setting type attribute: <br/>
    <fmt:formatNumber value="${num}" type="currency"/> <br/>
    Number after setting maxIntegerDigits and maxFractionDigits attribute:
    <br/>
    <fmt:formatNumber type="number" maxIntegerDigits="4" 
    maxFractionDigits="3" value="${num}" /> <br/>
    Number after setting pattern attribute: <br/>
    <fmt:formatNumber type="number" pattern="##,###.##" 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 43
 
Download this example.
 
Next Topic: JSTL fmt:parseNumber Formatting Tag with example.
Previous Topic: JSTL Formatting Tags with example.

 

Please follow and like us:
error
Posted in JSP   








Copyright © 2019 CodesJava DMCA.com Protection Status