Here you can find the source of mean(List
Parameter | Description |
---|---|
numbers | the numbers to calculate the mean. |
context | the MathContext. |
public static BigDecimal mean(List<BigDecimal> numbers, MathContext context)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.MathContext; import java.util.List; public class Main { /**/* w w w. j a v a2 s . c o m*/ * Returns the mean number in the numbers list. * * @param numbers the numbers to calculate the mean. * @param context the MathContext. * @return the mean of the numbers. */ public static BigDecimal mean(List<BigDecimal> numbers, MathContext context) { BigDecimal sum = sum(numbers); return sum.divide(new BigDecimal(numbers.size()), context); } /** * Returns the sum number in the numbers list. * * @param numbers the numbers to calculate the sum. * @return the sum of the numbers. */ public static BigDecimal sum(List<BigDecimal> numbers) { BigDecimal sum = new BigDecimal(0); for (BigDecimal bigDecimal : numbers) { sum = sum.add(bigDecimal); } return sum; } }