Reputation: 5655
I want to use fmt:formatNumber
to display the following:
.8 => 80%
-.8 => -80%
1721 => 1,721
1721 => +1,721
-7876 => -7,876
UPDATE: The format works perfectly for percent and grouping, but it doesn't work so well for putting a +
in front of a number, as in the following:
.8 => +80%
1721 => +1,721
How can I do this?
Upvotes: 3
Views: 1579
Reputation: 47951
You can use the %
pattern to "multiply by 100 and show as percentage". I think in your case you would need something like this:
// if num < 1 && num > -1 (or another logic)
<fmt:formatNumber value="${num}" format="%" />
// else
<fmt:formatNumber value="${num}" format="'+'###,###;'-'###,###" /> // show sign
UPDATE: You can use this method as well:
// if num < 1 && num > -1 (or another logic)
<fmt:formatNumber value="${num}" type="percentage" />
// else
<fmt:formatNumber value="${num}" type="number" groupingUsed="," />
Upvotes: 6