Java BigDecimal Round roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode)

Here you can find the source of roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode)

Description

Calculates the rounding error when dividend is divided by divisor

License

Apache License

Parameter

Parameter Description
dividend The dividend
divisor The devisor
roundingMode The rounding mode to use when dividing

Return

The rounding error

Declaration

public static BigDecimal roundingError(final BigDecimal dividend, final BigDecimal divisor,
        final int roundingMode) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {
    /**//from w w  w . j a  va  2  s . c  o m
     * Calculates the rounding error when <code>dividend</code> is divided by <code>divisor</code>
     *
     * @param dividend The dividend
     * @param divisor The devisor
     * @param roundingMode The rounding mode to use when dividing
     * @return The rounding error
     */
    public static BigDecimal roundingError(final BigDecimal dividend, final BigDecimal divisor,
            final int roundingMode) {
        return dividend.subtract(dividend.divide(divisor, divisor.scale(), roundingMode).multiply(divisor));
    }
}

Related

  1. roundDoubleAsBigDecimal(double d, int numberOfDecimals)
  2. roundDown(BigDecimal a)
  3. rounded(BigDecimal amount)
  4. roundHalfUp2Scale(BigDecimal value)
  5. roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode)
  6. roundOff(final BigDecimal amount)
  7. roundPrice(BigDecimal price, BigDecimal ticksize)
  8. roundTo(final BigDecimal bd, final int numberOfDecPlaces, final int finalScale)
  9. roundToMSDecimal(BigDecimal sourceDecimal)