【发布时间】:2011-07-27 08:32:09
【问题描述】:
如何将 123456789 的 int 值格式化为 123,456,789?
【问题讨论】:
标签: jsp number-formatting
如何将 123456789 的 int 值格式化为 123,456,789?
【问题讨论】:
标签: jsp number-formatting
使用 JSTL fmt:formatNumber
将你的模式设置为#,##0
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber pattern="#,##0" value="${value}" />
这将要求您在 WEB-INF/lib 文件夹中拥有 JSTL 标准标签库
http://tomcat.apache.org/taglibs/standard/
现在我不能 100% 确定,但大多数现代容器都提供“核心”API 库 jstl.jar,而您的 Web 应用程序必须提供实现。在上述链接的情况下,应该是下载中包含的standard.jar。
【讨论】:
javax.servlet.jsp.JspTagException: java.lang.IllegalArgumentException: Unexpected '0' in pattern "#,##0"
试试这个代码
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));
}
}
你可以在jsp块中写一个函数 和 main 方法中的代码。
【讨论】: