Format number in jsp

穿精又带淫゛_ 提交于 2019-12-10 14:13:51

问题


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


回答1:


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.




回答2:


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.




回答3:


NumberFormat: http://download.oracle.com/javase/1.4.2/docs/api/java/text/NumberFormat.html



来源:https://stackoverflow.com/questions/5508063/format-number-in-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!