1.在java中我想对金额进行格式化
2.两种情况
2.1 少于100
String money="10";
经过转换之后,输入为“0.10”(元).
2.2 大于100
String money="900";
经过转换之后,输入为“9.00”(元).
这是我之前写的,但是少于100就有问题了:
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;
}