String str = DecimalFormat.getNumberInstance().format(1245600000);
String currecy = NumberFormat.getCurrencyInstance().format(1245600000);
System.out.println("轉換成Currency格式:"+currecy);
System.out.println("轉換成帶千分位的格式:"+str);
輸出結果:
轉換成Currency格式:¥1,245,600,000.00
轉換成帶千分位的格式:1,245,600,000
也可以用js實現類似的功能:
function convert(num)
{ var str = num+"";
var reg = /(-?/d+)(/d{3})/;
while(reg.test(str)) {
str = str.replace(reg,"$1,$2");
}
return str;