JSTL <fmt:formatNumber>标签

<fmt:formatNumber>标签用于格式化数字,百分比和货币。

属性:

<fmt:formatNumber>标签具有以下属性:

属性 描述 必须? 默认
value Numeric value to display Yes None
type NUMBER, CURRENCY, or PERCENT No Number
pattern Specify a custom formatting pattern for the output. No None
currencyCode Currency code (for type="currency") No From the default locale
currencySymbol Currency symbol (for type="currency") No From the default locale
groupingUsed Whether to group numbers (TRUE or FALSE) No true
maxIntegerDigits Maximum number of integer digits to print No None
minIntegerDigits Minimum number of integer digits to print No None
maxFractionDigits Maximum number of fractional digits to print No None
minFractionDigits Minimum number of fractional digits to print No None
var Name of the variable to store the formatted number No Print to page
scope Scope of the variable to store the formatted number No page
  • 如果type属性是百分比或数字,那么您可以使用多个数字格式属性。maxIntegerDigits和minIntegerDigits属性允许你指定数量的nonfractional部分的大小。如果实际数目超过maxIntegerDigits,电话号码将被截断。

  • 还提供了属性,让你确定有多少小数位应该被使用。该minFractionalDigits和maxFractionalDigits属性允许你指定的小数位数。如果数目超过小数的最大位数,该数字将四舍五入。

  • 分组可以用来插入数千组逗号之间。分组是通过设置groupingIsUsed属性为true或false指定。当使用minIntegerDigits分组,要小心得到预期的结果。

  • 你可以选择要使用的模式属性。这个属性可指定希望的格式,如电话号码编码特殊字符。下表显示了这些代码。

Symbol 描述

0

Represents a digit.

E

Represents in exponential form.

#

Represents a digit; displays 0 as absent.

.

Serves as a placeholder for a decimal separator.

,

Serves as a placeholder for a grouping separator.

;

Separates formats.

-

Used as the default negative prefix.

%

Multiplies by 100 and displays as a percentage.

?

Multiplies by 1000 and displays as per mille.

¤

Represents the currency sign; replaced by actional currency symbol.

X

Indicates that any other characters can be used in the prefix or suffix.

'

Used to quote special characters in a prefix or suffix.

实例: