subtract Big Decimal - Java java.math

Java examples for java.math:BigDecimal Calculation

Description

subtract Big Decimal

Demo Code


import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        BigDecimal b = new BigDecimal("1234");
        BigDecimal item = new BigDecimal("1234");
        System.out.println(subtractBigDecimal(b,item));
    }/*  w  ww. j  a v a2  s  .c  o  m*/
    
    public static BigDecimal subtractBigDecimal(BigDecimal b,
            BigDecimal... item) {
        if (b == null)
            return null;
        BigDecimal r = b;
        if (item != null) {
            for (BigDecimal i : item) {
                r = r.subtract(i);
            }
        }
        return r;
    }
}

Related Tutorials