JSTL Core fmt formatNumber Tag

JSTL Core fmt formatNumber Tag

JSTL Core fmt:formatNumber Tag

Below is standard syntax to include in your JSP page:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

JSP example:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>fmt:formatDate example</h2>
<c:set var="amount" value="123456.8765432" />

<h3>Formatted number</h3>
<p>Input number: <fmt:formatNumber value="${amount}" 
pattern="###.#######"/></p>

<p>New formatted number: <fmt:formatNumber 
value="${amount}" pattern="###.##"/></p>

<p>New formatted number: <fmt:formatNumber 
value="${amount}" pattern="###.####"/></p>

<p>New formatted number: <fmt:formatNumber 
value="${amount}"/></p>

<p>New formatted number: <fmt:formatNumber 
value="${amount}" type="currency"/></p>

<p>New formatted number: <fmt:formatNumber 
value="${amount}" type="currency"/></p>

<p>UK currency: <fmt:setLocale value="en_GB"/>
<fmt:formatNumber value="${amount}" type="currency"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="percent" maxIntegerDigits="4"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="percent" minIntegerDigits="2"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="percent" minFractionDigits="2"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="percent" maxFractionDigits="5"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="number" minFractionDigits="2"/></p>

<p>New formatted number: <fmt:formatNumber value="${amount}" 
type="number" maxFractionDigits="5"/></p>


</body>
</html>

Output:

JSTL Core fmt formatNumber Tag

 

 

download Download Project: jstl-1.2

Leave a Reply

Your email address will not be published. Required fields are marked *