<fmt:formatNumber>
Syntax 1: without a body
<fmt:formatNumber value=”numericValue”
[type=”{number|currency|percent}”]
[pattern=”customPattern”]
[currencyCode=”currencyCode”]
[currencySymbol=”currencySymbol”]
[groupingUsed=”{true|false}”]
[maxIntegerDigits=”maxIntegerDigits”]
[minIntegerDigits=”minIntegerDigits”]
[maxFractionDigits=”maxFractionDigits”]
[minFractionDigits=”minFractionDigits”]
[var=”varName”]
[scope=”{page|request|session|application}”]/>
Syntax 2: with a body to specify the numeric value to be formatted
<fmt:formatNumber [type=”{number|currency|percent}”]
[pattern=”customPattern”]
[currencyCode=”currencyCode”]
[currencySymbol=”currencySymbol”]
[groupingUsed=”{true|false}”]
[maxIntegerDigits=”maxIntegerDigits”]
[minIntegerDigits=”minIntegerDigits”]
[maxFractionDigits=”maxFractionDigits”]
[minFractionDigits=”minFractionDigits”]
[var=”varName”]
[scope=”{page|request|session|application}”]>
numeric value to be formatted
</fmt:formatNumber>
参数说明:
Value:要格式化的值
Type:怎样进行格式化,如货币(currency),百分比(percent),数字(number)
Pattern:以怎样的格式进行格式化,可以自定义输出格式
currencySymbol:当前货币符号,如¥,$
groupingUsed:是否进行分组输出,会对数字三个一组进行输出
maxIntegerDigits:整数位最大多数位
minIntegerDigits:整数位最少多数位
maxFractionDigits:小数位最多多少位
minFractionDigits:小数位最少多少位
如:代码
<body> <h1>测试jstl格式化库</h1> <hr> <li>测试日期的格式化</li><br> today(default):<fmt:formatDate value="${today}"/><br> today(type="date"):<fmt:formatDate value="${today}" type="date"/><br> today(type="time"):<fmt:formatDate value="${today}" type="time"/><br> today(type="both"):<fmt:formatDate value="${today}" type="both"/><br> today(dateStyle="short"):<fmt:formatDate value="${today}" dateStyle="short"/><br> today(dateStyle="medium"):<fmt:formatDate value="${today}" dateStyle="medium"/><br> today(dateStyle="long"):<fmt:formatDate value="${today}" dateStyle="long"/><br> today(dateStyle="full"):<fmt:formatDate value="${today}" dateStyle="full"/><br> today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss"/><br> today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/><br> ${d }<br> <p> <li>测试数字的格式化</li><br> n(default):<fmt:formatNumber value="${n}"/><br> n(pattern="###,###.##"):<fmt:formatNumber value="${n}" pattern="###,###.##"/><br> n(pattern="###,###.0000"):<fmt:formatNumber value="${n}" pattern="###,###.0000"/><br> n(groupingUsed="false"):<fmt:formatNumber value="${n}" groupingUsed="false"/><br> n(minIntegerDigits="10"):<fmt:formatNumber value="${n}" minIntegerDigits="10"/><br> n(type="currency"):<fmt:formatNumber value="${n}" type="currency"/><br> n(type="currency"):<fmt:formatNumber value="${n}" type="currency" currencySymbol="$"/><br> n(type="percent"):<fmt:formatNumber value="${p}" type="percent" maxFractionDigits="2" minFractionDigits="2"/><br> </body>