YouTip LogoYouTip

Jstl Format Formatnumber Tag

[![Image 1: JSP Standard Tag Library](#)JSP Standard Tag Library](#) The `` tag is used to format numbers, percentages, and currencies. ### Syntax Format <fmt:formatNumber value="" type="" pattern="" currencyCode="" currencySymbol="" groupingUsed="" maxIntegerDigits="" minIntegerDigits="" maxFractionDigits="" minFractionDigits="" var="" scope=""/> ### Attributes The `` tag has the following attributes: | **Attribute** | **Description** | **Required** | **Default Value** | | --- | --- | --- | --- | | value | The number to be displayed | Yes | None | | type | NUMBER, CURRENCY, or PERCENT type | No | Number | | pattern | Specifies a custom formatting pattern for output | No | None | | currencyCode | Currency code (when type="currency") | No | Depends on default locale | | currencySymbol | Currency symbol (when type="currency") | No | Depends on default locale | | groupingUsed | Whether to group numbers (TRUE or FALSE) | No | true | | maxIntegerDigits | Maximum number of integer digits | No | None | | minIntegerDigits | Minimum number of integer digits | No | None | | maxFractionDigits | Maximum number of digits after the decimal point | No | None | | minFractionDigits | Minimum number of digits after the decimal point | No | None | | var | Variable to store the formatted number | No | Print to page | | scope | Scope of the var attribute | No | page | If the type attribute is percent or number, you can use several other number formatting attributes. The maxIntegerDigits and minIntegerDigits attributes allow you to specify the length of the integer. If the actual number exceeds the maximum value specified by maxIntegerDigits, the number will be truncated. Some attributes allow you to specify the number of digits after the decimal point. The minFractionDigits and maxFractionDigits attributes allow you to specify the number of digits after the decimal point. If the actual number exceeds the specified range, the number will be truncated. Number grouping can be used to insert a comma every three digits. The groupingUsed attribute specifies whether to use number grouping. When used with the minIntegerDigits attribute, you must be careful to achieve the expected result. You might use the pattern attribute. This attribute allows you to include specific characters when formatting numbers. The following table lists these characters. | **Symbol** | **Description** | | --- | --- | | 0 | Represents a digit | | E | Uses exponential format | | # | Represents a digit, displays 0 if absent; leading and trailing zeros are not displayed. | | . | Decimal point | | , | Number grouping separator | | ; | Separates formats | | - | Uses the default negative prefix | | % | Percentage | | ? | Per mille | | Β€ | Currency symbol, replaced with the actual currency symbol | | X | Specifies characters that can be used as prefixes or suffixes | | ' | Quotes special characters in a prefix or suffix | * * * ## Example JSTL fmt:formatNumber Tag

Number Formatting:

Formatted Number (1):

Formatted Number (2):

Formatted Number (3):

Formatted Number (4):

Formatted Number (5):

Formatted Number (6):

Formatted Number (7):

Formatted Number (8):

US Dollar :

The output is as follows: Number Formatting:Formatted Number (1): οΏ₯120,000.23Formatted Number (2): 000.231Formatted Number (3): 120,000.231Formatted Number (4): 120000.231Formatted Number (5): 023%Formatted Number (6): 12,000,023.0900000000%Formatted Number (7): 023%Formatted Number (8): 120E3US Dollar : $120,000.23 * * JSP Standard Tag Library](#)
← Jstl Format Parsenumber TagJstl Core Url Tag β†’