泛型为Map的List集合中Double和BigDecimal类型数据求和
1》Double类型
Double pfs = collects.stream().mapToDouble(c -> CommonUtils.isNumber(StringUtil.nvl(c.get(“pfs”), “0”)) ?
Double.parseDouble(StringUtil.nvl(c.get(“pfs”), “0”)) : 0.00).summaryStatistics().getSum();
2》BigDecimal类型
BigDecimal pfs = collects.stream().map(m -> {
BigDecimal bigDecimal = BigDecimal.valueOf(0.00);
try {
bigDecimal = new BigDecimal(StringUtil.nvl(m.get(“pfs”), “0”));
} catch (Exception e) {
bigDecimal = BigDecimal.valueOf(0.00);
} finally {
return bigDecimal;
}
}).reduce(BigDecimal.ZERO, BigDecimal::add);