Java BigDecimal Multiply multiplyFactor(BigDecimal val, float factor)

Here you can find the source of multiplyFactor(BigDecimal val, float factor)

Description

Vermenigvuldigt een BigDecimal met een factor.

License

Open Source License

Parameter

Parameter Description
val BigDecimal
factor te vermenigvuldigen factor

Return

retourneert nooit null

Declaration

public static BigDecimal multiplyFactor(BigDecimal val, float factor) 

Method Source Code


//package com.java2s;
/*//from  ww w .j a v  a  2s  . c om
 * B3P Commons Core is a library with commonly used classes for webapps.
 * Included are clieop3, oai, security, struts, taglibs and other
 * general helper classes and extensions.
 *
 * Copyright 2000 - 2008 B3Partners BV
 * 
 * This file is part of B3P Commons Core.
 * 
 * B3P Commons Core is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * B3P Commons Core is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with B3P Commons Core.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Vermenigvuldigt een BigDecimal met een factor. De factor
     * wordt omgezet in een BigDecimal met een scale van 5.
     * @param val BigDecimal
     * @param factor te vermenigvuldigen factor
     * @return retourneert nooit null
     */
    public static BigDecimal multiplyFactor(BigDecimal val, float factor) {
        int scale = 5;
        return multiplyFactor(val, factor, scale);
    }

    public static BigDecimal multiplyFactor(BigDecimal val, float factor, int scale) {
        if (val == null) {
            return new BigDecimal("0");
        }
        BigDecimal bdFactor = new BigDecimal(factor);
        BigDecimal result = val.multiply(bdFactor);
        return result.setScale(scale, BigDecimal.ROUND_HALF_UP);
    }
}

Related

  1. multiply(BigDecimal value, Integer multiplier)
  2. multiply(BigDecimal... operands)
  3. multiply(final BigDecimal val1, final BigDecimal val2)
  4. multiply(final BigDecimal value, final BigDecimal multiplicand)
  5. multiplyBy(BigDecimal multiplicand, BigDecimal multiplier)
  6. multiplyMoeda(BigDecimal val1, BigDecimal val2)
  7. multiplyQtde(BigDecimal val1, BigDecimal val2)