Reputation: 1323
Because I need to write out my objects in many templates in my app, I created own EL tag. Now I need to format numbers for myself. Is there a way how to use in this tag library class possibilities that provides formatNumber
tag in JSP template? Does formatNumber
tag uses some external library which I can use?
<fmt:formatNumber type="number" value="${orders.getStatistics().getMin()}" maxFractionDigits="1" />
I need only two format types (number and percent)
Upvotes: 0
Views: 240
Reputation: 1108802
It is just using the standard Java SE API provided java.text.NumberFormat
under the covers.
The tag's job can be represented in plain Java as follows, leaving locale outside consideration as you didn't specify it in your tag example (even though that would be pretty important to consider):
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(1);
String result = formatter.format(number);
Upvotes: 1