Java BigDecimal Multiply multiplyBy(BigDecimal multiplicand, BigDecimal multiplier)

Here you can find the source of multiplyBy(BigDecimal multiplicand, BigDecimal multiplier)

Description

Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()) .

License

Open Source License

Return

this * multiplicand

Declaration

protected static BigDecimal multiplyBy(BigDecimal multiplicand, BigDecimal multiplier) 

Method Source Code

//package com.java2s;
/*//from w w  w  .  ja v  a 2  s. c om
 The MIT License (MIT)
    
 Copyright (c) <year> <copyright holders>
    
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
    
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
    
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

import static java.math.RoundingMode.HALF_EVEN;

import java.math.BigDecimal;

public class Main {
    /**
     * Returns a {@code BigDecimal} whose value is <tt>(this &times;
      * multiplicand)</tt>, and whose scale is {@code (this.scale() +
      * multiplicand.scale())}.
     * 
     * @return {@code this * multiplicand}
     */
    protected static BigDecimal multiplyBy(BigDecimal multiplicand, BigDecimal multiplier) {
        return setScale(multiplicand.multiply(multiplier));
    }

    /**
     * Returns a {@code BigDecimal} whose scale is the specified value, and
     * whose unscaled value is determined by multiplying or dividing this
     * {@code BigDecimal}'s unscaled value by the appropriate power of ten to
     * maintain its overall value. If the scale is reduced by the operation, the
     * unscaled value must be divided (rather than multiplied), and the value
     * may be changed; in this case, the specified rounding mode is applied to
     * the division.
     * 
     * @param bigDecimal
     *            The value of the BigDecimal
     * @return a {@code BigDecimal} whose scale is the specified value, and
     *         whose unscaled value is determined by multiplying or dividing
     *         this {@code BigDecimal}'s unscaled value by the appropriate power
     *         of ten to maintain its overall value.
     */
    protected static BigDecimal setScale(BigDecimal bigDecimal) {
        return bigDecimal.setScale(4, HALF_EVEN);
    }
}

Related

  1. multiply(BigDecimal v1, BigDecimal v2)
  2. multiply(BigDecimal value, Integer multiplier)
  3. multiply(BigDecimal... operands)
  4. multiply(final BigDecimal val1, final BigDecimal val2)
  5. multiply(final BigDecimal value, final BigDecimal multiplicand)
  6. multiplyFactor(BigDecimal val, float factor)
  7. multiplyMoeda(BigDecimal val1, BigDecimal val2)
  8. multiplyQtde(BigDecimal val1, BigDecimal val2)