工作中遇到BigDecimal格式化问题,手中无jdk手册,只好百度一下,这种问题,用百度还是找得到滴。
解决如下:
/**
* Fortmat BigDecimal while the number is too long.
* for example: the param value = 1222222.222222,
* and then the return will be 1,222,222.22 . It depends on NumberFormat.getInstance() .
* @param value
* @return
*/
public String formatValue(Object value){
String content = null;
if (value == null) {
content = "";
} else {
if(value instanceof BigDecimal){
//conver to fortmat String
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
content = nf.format(value);
}else{
content = String.valueOf(value);
}
}
return content;
}