日期:2014-05-20  浏览次数:20630 次

有现成的方法把数字换成金额格式999,999,999的吗,就是每三位逗好隔开
?

------解决方案--------------------

DecimalFormat myFormatter = new DecimalFormat( "###,###,###.## ");
String output = myFormatter.format(value);
System.out.println(output);

------解决方案--------------------
要带改成其他货币符号的话,改里面的“$”就可以了。

String str = String.format( "$%,.2f ", num + 0.0);
System.out.println(str);
------解决方案--------------------
public String getCurrency (String aCurrency)
{ if (aCurrency == null || aCurrency.length() == 0)
return " ";
try
{
double dCurr= Double.parseDouble(aCurrency);
dCurr /= 100;
java.text.DecimalFormat dFmt= new java.text.DecimalFormat( "#,##0.00 ");
return dFmt.format(dCurr);
}
catch (Exception ex)
{
return aCurrency;
}
}

自己写个bean放到top.jsp里
以后每个jsp页面include这个top.jsp
调用这个方法就可以
just try