Project

General

Profile

Download (1.02 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.common;
10

    
11
import java.math.BigDecimal;
12
import java.math.RoundingMode;
13
import java.util.Set;
14

    
15
/**
16
 * @author a.mueller
17
 * @since 25.04.2020
18
 */
19
public final class BigDecimalUtil {
20

    
21
    public static final BigDecimal MAX_BIGDECIMAL = BigDecimal.valueOf(Double.MAX_VALUE);
22

    
23
    public static final BigDecimal MIN_BIGDECIMAL = BigDecimal.valueOf(Double.MIN_VALUE);
24

    
25
    public static BigDecimal average(Set<BigDecimal> bigDecimals) {
26
        BigDecimal sum = BigDecimal.ZERO;
27
        int count=0;
28
        for(BigDecimal bigDecimal : bigDecimals) {
29
            if(null != bigDecimal) {
30
                sum = sum.add(bigDecimal);
31
                count++;
32
            }
33
        }
34
        return sum.divide(new BigDecimal(count), RoundingMode.HALF_EVEN);
35
    }
36
}
(2-2/25)