Jsp format number

How do I format int value 123456789 as 123,456,789 ?

+4
source share
3 answers

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.

+1
source

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 template to #, ## 0

 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <fmt:formatNumber pattern="#,##0" value="${value}" /> 

This will require the JSTL Standard tag library in the WEB-INF / lib folder

http://tomcat.apache.org/taglibs/standard/

Now I'm not 100% sure, but most modern containers provide the "main" jstl.jar API library, and your web application should provide an implementation. In the case of the above link, which should be the standard .jar included in the download.

+14
source

Source: https://habr.com/ru/post/1346150/


All Articles