formatNumber
目的 Purpose
Formats a number using the patterns defined by the DecimalFormat class. Also supports attributes used in the JSTL formatNumber
tag.使用例 Examples
<g:formatNumber number="${myNumber}" format="\\$###,##0" />
<g:formatNumber number="${myCurrencyAmount}" type="currency" currencyCode="EUR" />
<g:formatNumber number="${myCurrencyAmount}" type="currency" currencyCode="USD" />
<g:formatNumber number="${myNumber}" type="number" minIntegerDigits="9" />
<g:formatNumber number="${myNumber}" type="number" maxFractionDigits="2" />
<g:formatNumber number="${myNumber}" type="number"
maxFractionDigits="2" roundingMode="HALF_DOWN" />
詳細 Description
属性 Attributes
number
(required) - The number object to formateformat
(optional) - The formatting pattern to use for the number, see DecimalFormatformatName
(optional) - Look upformat
from the default MessageSource / ResourceBundle (i18n/.properties file) with this key. Look upformat
from the default MessageSource / ResourceBundle (i18n/.properties file) with this key. Ifformat
andformatName
are empty,format
is looked up with 'default.number.format
' key. If the key is missing, '0' formatting pattern is used.type
(optional) - The type of formatter to use: 'number', 'currency' or 'percent' .format
orformatName
aren't used whentype
is specified.locale
(optional) - Override the locale of the request , String or Locale valuegroupingUsed
(optional) - Set whether grouping will be used in this format.minIntegerDigits
(optional) - Sets the minimum number of digits allowed in the integer portion of a number.maxIntegerDigits
(optional) - Sets the maximum number of digits allowed in the integer portion of a number.minFractionDigits
(optional) - Sets the minimum number of digits allowed in the fraction portion of a number.maxFractionDigits
(optional) - Sets the maximum number of digits allowed in the fraction portion of a number.currencyCode
(optional) - The standard currency code ('EUR', 'USD', etc.), uses formatting settings for the currency. type='currency' attribute is recommended.currencySymbol
(optional) - Force the currency symbol to some symbol, recommended way is to usecurrencyCode
attribute instead (takes symbol information from Currency)roundingMode
(optional) - Sets the RoundingMode used in this DecimalFormat. Usual values:HALF_UP
,HALF_DOWN
. If roundingMode isUNNECESSARY
and anArithemeticException
occurs, the original number formatted with default number formatting will be returned.