How do I format an int value of 123456789
as 123,456,789
?
Use JSTL fmt:formatNumber
http://download.oracle.com/docs/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatNumber.html
Set your pattern to #,##0
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber pattern="#,##0" value="${value}" />
This will require you having The JSTL Standard tag library in your WEB-INF/lib folder
http://tomcat.apache.org/taglibs/standard/
Now I'm not 100% sure, but most modern containers provide the "core" API library jstl.jar and your web app must provide the implemenation. In the case of the above link that should be standard.jar included with the download.
try this code
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
DecimalFormat formatter = new DecimalFormat("###,###,###");
System.out.print(formatter.format(123456789));
}
}
you can write a function in jsp block <%! %> and the code inside the main method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With