2011-04-01 58 views

回答

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)); 
} 

}

您可以在JSP塊<%編寫一個函數! %>和main方法中的代碼。

+0

太棒了!謝謝! – mysticfalls 2011-04-01 02:05:33

+1

儘量不要在現代應用中使用scriptlets <% %>。儘可能使用JSTL。 – 2011-04-01 02:11:58

+0

@Dave G你是對的 – Nathanphan 2011-04-01 02:16:57

14

使用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}" /> 

這需要你遇到的JSTL標準標籤庫在您的WEB-INF/lib文件夾中

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

現在我不是100%確定,但大多數現代容器提供了「核心」API庫jstl.jar並且您的Web應用程序必須提供實現。在上面的鏈接應該是standard.jar包含在下載的情況下。

+0

嗨我試過你的答案,但我得到一個錯誤「絕對uri http://java.sun.com/jsp/jstl/fmt不能解決在web.xml或jar ...」 – mysticfalls 2011-04-01 01:38:11

+0

對不起我曾假設你已經將JSTL添加到你的網絡應用程序中。 – 2011-04-01 02:08:43

+1

@DaveG:你的模式需要糾正。目前它是'#,### 0',應該是'#,## 0'。 – 2013-07-26 14:56:54