`
xiongzhenhui
  • 浏览: 205434 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

DecimalFormat格式化数字

 
阅读更多

 public String getIntegerData(Object value) {
  if (value != null && StringUtil.isBlankOrNull(value.toString()))
   return "0";
  BigDecimal num = new BigDecimal(value.toString());
  DecimalFormat format = new DecimalFormat("###,###");
  return format.format(num).toString();
 }

 

 public String getBigDecimalData(Object value) {
  if (value != null && StringUtil.isBlankOrNull(value.toString()))
   return "0";
  BigDecimal num = new BigDecimal(value.toString());
  DecimalFormat format = new DecimalFormat("###,##0.##");
  return format.format(num).toString();
 }

 

其中#代表如果有匹配则匹配,如果没有匹配则为空,0表示如果有匹配则匹配,如果没有匹配则为0

如1和1.2如果使用"###,##0.##"则转换后为1和1.2,如果使用"###,##0.00"则转换后为1.00和1.20

  • 大小: 18.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics