I was responsible for just a website, there is a bug, not encountered before, and production environments running for 4/5 years the problem did not happen, it happened today. So checked: Usage <fmt formatNumber> tag, record it himself.
<Fmt: formatNumber> tag is used to format numbers, percentage, currency.
Attributes
<Fmt: formatNumber> tag has the following attributes:
Attributes | description | If necessary | Defaults |
---|---|---|---|
value | Figures to be displayed | Yes | no |
type | NUMBER, CURRENCY, or type PERCENT | no | Number |
pattern | Specify a custom formatting patterns with the output | no | no |
currencyCode | Currency Code (if type = "currency" time) | no | It depends on the default region |
currencySymbol | Currency symbol (when type = "currency" time) | no | It depends on the default region |
groupingUsed | Whether the digital packet (TRUE or FALSE) | no | true |
maxIntegerDigits | The maximum number of integer digits | no | no |
minIntegerDigits | The smallest integer digits | no | no |
maxFractionDigits | The maximum number of digits after the decimal point | no | no |
minFractionDigits | The minimum number of digits after the decimal point | no | no |
where | Variable storage format numbers | no | Print to page |
scope | Scope var attributes | no | page |
If the type attribute is the percent or number, then you can use several other formatting numeric attributes. maxIntegerDigits property and minIntegerDigits property allows you to specify the length of integers. If the actual number exceeds the maximum specified maxIntegerDigits, the number will be truncated.
Some attribute allows you to specify the number of digits after the decimal point. minFractionalDigits property and maxFractionalDigits property allows you to specify the number of digits after the decimal point. If the actual number exceeds the specified range, this number will be truncated.
Digital Packet may be used to insert a comma in each of the three numbers. groupingIsUsed attribute is used to specify whether to use digital packet. When used in conjunction with minIntegerDigits property, it must be very careful to get the desired result.
You might use the pattern attribute. This attribute allows you to include the specified character when the digital encoding. The following table lists these characters.
symbol | description |
---|---|
0 | A representative figures |
E | Exponential format |
# | A representative number, if not then display 0 |
. | Decimal point |
, | Digital packet delimiter |
; | Delimited format |
- | Use the default negative prefix |
% | percentage |
? | Mille |
¤ | Currency symbol, instead of using actual currency symbol |
X | Designated as a prefix or suffix character |
' | Quote special characters in a prefix or suffix |
Examples of presentation
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>JSTL fmt:formatNumber Tag</title> </head> <body> <h3>Number Format:</h3> <c:set var="balance" value="120000.2309" /> <p>Formatted Number (1): <fmt:formatNumber value="${balance}" type="currency"/></p> <p>Formatted Number (2): <fmt:formatNumber type="number" maxIntegerDigits="3" value="${balance}" /></p> <p>Formatted Number (3): <fmt:formatNumber type="number" maxFractionDigits="3" value="${balance}" /></p> <p>Formatted Number (4): <fmt:formatNumber type="number" groupingUsed="false" value="${balance}" /></p> <p>Formatted Number (5): <fmt:formatNumber type="percent" maxIntegerDigits="3" value="${balance}" /></p> <p>Formatted Number (6): <fmt:formatNumber type="percent" minFractionDigits="10" value="${balance}" /></p> <p>Formatted Number (7): <fmt:formatNumber type="percent" maxIntegerDigits="3" value="${balance}" /></p> <p>Formatted Number (8): <fmt:formatNumber type="number" pattern="###.###E0" value="${balance}" /></p> <p>Currency in USA : <fmt:setLocale value="en_US"/> <fmt:formatNumber value="${balance}" type="currency"/></p> </body> </html>
Results are as follows:
NUMBER FORMAT: Formatted Number (1): £120,000.23 Formatted Number (2): 000.231 Formatted Number (3): 120,000.231 Formatted Number (4): 120000.231 Formatted Number (5): 023% Formatted Number (6): 12,000,023.0900000000% Formatted Number (7): 023% Formatted Number (8): 120E3 Currency in USA : $120,000.23
note:
If not attribute groupingUsed = 'false' tag will automatically defaults to true after formatting. The default is true effect is 1000. If you require el expression in digital computing, it will error. Because it defaults to string, can not be calculated.