原貼地址:https://bbs.csdn.net/topics/390418233
顯示結果爲小數點後保留2位,小數點前每3位一個逗號。
public String getDecimalFormat(String str){
Integer initValue=0;
String outStr = "";
if(str!=null&&!"".equals(str.trim())){
initValue=Integer.parseInt(str);
Integer yuanValue=initValue/100;
DecimalFormat fmt = new DecimalFormat("##,###,###,###,###.00");
double d;
try {
d = Double.parseDouble(String.valueOf(yuanValue));
outStr = fmt.format(d);
} catch (Exception e) {
e.printStackTrace();
}
}
return outStr;
}