jsp中的格式编号

mys*_*lls 5 jsp number-formatting

我如何格式化的int值123456789作为123,456,789

Dav*_*e G 15

使用JSTL fmt:formatNumber

http://download.oracle.com/docs/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatNumber.html

将您的模式设置为#,## 0

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

这将要求您在WEB-INF/lib文件夹中具有JSTL标准标记库

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

现在我不是100%肯定,但大多数现代容器提供"核心"API库jstl.jar,您的Web应用程序必须提供实现.在上述链接的情况下,下载中应包含standard.jar.


Nat*_*han 1

试试这个代码

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));
}
Run Code Online (Sandbox Code Playgroud)

}

你可以在jsp块中编写一个函数 <%! %> 以及 main 方法内的代码。