JSTL 详解03

<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 :小数位最少多少位

如:代码

Html代码
  1. < body >   
  2.     < h1 > 测试jstl格式化库 </ h1 >   
  3.     < hr >   
  4.     < li > 测试日期的格式化 </ li > < br >   
  5.     today(default):< fmt:formatDate   value = "${today}" /> < br >   
  6.     today(type = "date" ): < fmt:formatDate   value = "${today}"   type = "date" /> < br >   
  7.     today(type = "time" ): < fmt:formatDate   value = "${today}"   type = "time" /> < br >   
  8.     today(type = "both" ): < fmt:formatDate   value = "${today}"   type = "both" /> < br >   
  9.     today(dateStyle = "short" ): < fmt:formatDate   value = "${today}"   dateStyle = "short" /> < br >   
  10.     today(dateStyle = "medium" ): < fmt:formatDate   value = "${today}"   dateStyle = "medium" /> < br >   
  11.     today(dateStyle = "long" ): < fmt:formatDate   value = "${today}"   dateStyle = "long" /> < br >   
  12.     today(dateStyle = "full" ): < fmt:formatDate   value = "${today}"   dateStyle = "full" /> < br >   
  13.     today(pattern = "yyyy/MM/dd HH:mm:ss" ): < fmt:formatDate   value = "${today}"   pattern = "yyyy/MM/dd HH:mm:ss" /> < br >   
  14.     today(pattern = "yyyy/MM/dd HH:mm:ss" ): < fmt:formatDate   value = "${today}"   pattern = "yyyy/MM/dd HH:mm:ss"   var = "d" /> < br >   
  15.     ${d }< br >   
  16.     < p >   
  17.     < li > 测试数字的格式化 </ li > < br >   
  18.     n(default):< fmt:formatNumber   value = "${n}" /> < br >   
  19.     n(pattern = "###,###.##" ): < fmt:formatNumber   value = "${n}"   pattern = "###,###.##" /> < br >   
  20.     n(pattern = "###,###.0000" ): < fmt:formatNumber   value = "${n}"   pattern = "###,###.0000" /> < br >   
  21.     n(groupingUsed = "false" ): < fmt:formatNumber   value = "${n}"   groupingUsed = "false" /> < br >   
  22.     n(minIntegerDigits = "10" ): < fmt:formatNumber   value = "${n}"   minIntegerDigits = "10" /> < br >   
  23.     n(type = "currency" ): < fmt:formatNumber   value = "${n}"   type = "currency" /> < br >   
  24.     n(type = "currency" ): < fmt:formatNumber   value = "${n}"   type = "currency"   currencySymbol = "$" /> < br >   
  25.     n(type = "percent" ): < fmt:formatNumber   value = "${p}"   type = "percent"   maxFractionDigits = "2"   minFractionDigits = "2" /> < br >   
  26. </ body >   
<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>

 

JSTL 详解03

你可能感兴趣的:(jstl)