Returns the sum number in the BigDecimal list. - Java java.math

Java examples for java.math:BigDecimal

Description

Returns the sum number in the BigDecimal list.

Demo Code


//package com.java2s;
import java.math.BigDecimal;

import java.util.List;

public class Main {


    /**/*from   ww  w .  j  a v a 2s  .  c  o m*/
     * 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;
    }
}

Related Tutorials