產品要求頁面金額展現時要去除多餘的零:1.25展現1.25,1.20展現1.2,1.00 展現1。java
public static String wipeBigDecimalZero(BigDecimal number) { NumberFormat nf = NumberFormat.getInstance(); return nf.format(number); } public static void wipeMapBigDecimalZero(Map<String,Object> map) { for(Map.Entry<String, Object> entry:map.entrySet()) { if(entry.getValue() instanceof BigDecimal) { map.put(entry.getKey(), NumberFormatUtil.wipeBigDecimalZero((BigDecimal)entry.getValue())); } } } public static void wipeListOrMapBigDecimalZero(Object collection) { if(collection instanceof Map) { Map<String,Object> map = (Map<String,Object>)collection; for(Map.Entry<String, Object> entry:map.entrySet()) { if(entry.getValue() instanceof BigDecimal) { map.put(entry.getKey(), NumberFormatUtil.wipeBigDecimalZero((BigDecimal)entry.getValue())); } } } if(collection instanceof List) { List<Object> list = (List<Object>) collection; for (Object object : list) { if(object instanceof Map) { Map<String,Object> map = (Map<String,Object>)object; for(Map.Entry<String, Object> entry:map.entrySet()) { if(entry.getValue() instanceof BigDecimal) { map.put(entry.getKey(), NumberFormatUtil.wipeBigDecimalZero((BigDecimal)entry.getValue())); } } } } } }