示例
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>JSTL fmt:formatNumber Tag</title>
</head>
<body>
<h3>Number Format:</h3>
<c:set var = "balance" value = "120000.2309" />
<p>Formatted Number (1): <fmt:formatNumber value = "${balance}"
type = "currency"/></p>
<p>Formatted Number (2): <fmt:formatNumber type = "number"
maxIntegerDigits = "3" value = "${balance}" /></p>
<p>Formatted Number (3): <fmt:formatNumber type = "number"
maxFractionDigits = "3" value = "${balance}" /></p>
<p>Formatted Number (4): <fmt:formatNumber type = "number"
groupingUsed = "false" value = "${balance}" /></p>
<p>Formatted Number (5): <fmt:formatNumber type = "percent"
maxIntegerDigits="3" value = "${balance}" /></p>
<p>Formatted Number (6): <fmt:formatNumber type = "percent"
minFractionDigits = "10" value = "${balance}" /></p>
<p>Formatted Number (7): <fmt:formatNumber type = "percent"
maxIntegerDigits = "3" value = "${balance}" /></p>
<p>Formatted Number (8): <fmt:formatNumber type = "number"
pattern = "###.###E0" value = "${balance}" /></p>
<p>Currency in USA :
<fmt:setLocale value = "en_US"/>
<fmt:formatNumber value = "${balance}" type = "currency"/>
</p>
</body>
</html>
这将产生以下结果-
Number Format:
Formatted Number (1): £120,000.23
Formatted Number (2): 000.231
Formatted Number (3): 120,000.231
Formatted Number (4): 120000.231
Formatted Number (5): 023%
Formatted Number (6): 12,000,023.0900000000%
Formatted Number (7): 023%
Formatted Number (8): 120E3
Currency in USA : $120,000.23