Java BigDecimal getMean(final BigDecimal... vals)

Here you can find the source of getMean(final BigDecimal... vals)

Description

get Mean

License

Open Source License

Declaration

protected static BigDecimal getMean(final BigDecimal... vals) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    protected static BigDecimal getMean(final BigDecimal... vals) {
        int count = 0;
        BigDecimal sum = new BigDecimal(0);

        for (final BigDecimal d : vals) {
            if (d == null) {
                continue;
            }//from  ww  w. j  a va  2 s .  c om
            sum = sum.add(d);
            count++;
        }

        if (count == 0) {
            return null;
        }
        return sum.divide(new BigDecimal(count), BigDecimal.ROUND_HALF_UP);

    }
}

Related

  1. getLetJp(BigDecimal nl)
  2. getLocalHourMinute(BigDecimal gmtHour)
  3. getMaxBigDecimal(@Nonnull final BigDecimal aValue, @Nonnull final BigDecimal... aValues)
  4. getMaxBigDecimal(int precision, int scale)
  5. getMaxPrecision(BigDecimal... decimals)
  6. getMicroSec(BigDecimal hours)
  7. getNumberAsBigDecimal(Number value)
  8. getNumberOfDecimalPlaces(BigDecimal bigDecimal)
  9. getParamBigDecimal(Map paramMap, String paramName)