I would like to format a number in JSTL in ways it will look like:
<c:set var="num" value="12345678000199"/>
<fmt:formatNumber type="number" value="${num}" pattern=?/>
<!-- desired output: 12.345.678/0001-99 (Brazilian CNPJ [companies' IRS ID])-->
Thanks in advance!!
That’s not possible with standard JSTL tags nor with the standard
NumberFormatAPI which it is using under the covers. You’d need to create a custom JSP tag or EL function for that. You could achieve the job with simpleStringmanipulation methods or even (ab)use Swing’sMaskFormatter:With an EL function you can ultimately end up like this:
For more detail on creating an EL function, see also the bottom of Hidden features of JSP/Servlet.