I want to sum the cost property of items in a List.
I have written a stream to collect these items and perform the sum, using groupingBy(), as illustrated below.
groupingBy(
...,
...,
Collectors.summingDouble(e->e.cost.doubleValue())
)
However, the cost field is a BigDecimal. In the code above, I am converting it to double, which makes me cringe. Is there a "drop-in" method I can write to that effect ? That would be an equivalent of summingBigDecimal(), which does not exist.
This is not a duplicate of Adding up BigDecimals using Streams as the answers are not applicable inside a groupingBy. Agreed with Anthony Garcia.