I have this piece of code that sets a BigDecimal:
setTotalDogsCurrentValueInUsd(
purchases
.stream()
.map(p -> p.getNumberOfDogs())
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(rate)));
I would like to add MathContext.DECIMAL32 to round but I don't know where to add it exaclty
use this overload of multiply:
.multiply(new BigDecimal(rate), MathContext.DECIMAL32)
or if you want to apply it during the reduce call:
.reduce(BigDecimal.ZERO, (a, b) -> a.add(b, MathContext.DECIMAL32))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With