Here you can find the source of average(final BigDecimal... numbers)
public static BigDecimal average(final BigDecimal... numbers)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.math.RoundingMode; import java.util.stream.IntStream; public class Main { public static BigDecimal average(final BigDecimal... numbers) { return IntStream.range(0, numbers.length).mapToObj(i -> numbers[i]).reduce((sum, next) -> sum.add(next)) .map(sum -> sum.divide(BigDecimal.valueOf(numbers.length))).orElse(BigDecimal.ZERO); }/*ww w . j a v a 2s . c o m*/ public static BigDecimal divide(final BigDecimal amount, final BigDecimal divideBy, final int scale) { return amount.setScale(scale, RoundingMode.HALF_EVEN).divide(divideBy, RoundingMode.HALF_EVEN); } }