Java BigDecimal Round roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode)

Here you can find the source of roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode)

Description

round Impl

License

Open Source License

Declaration

private static BigDecimal roundImpl(final BigDecimal number, final int minFractionDigits,
            final int maxFractionDigits, final RoundingMode mode) 

Method Source Code


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

public class Main {
    private static BigDecimal roundImpl(final BigDecimal number, final int minFractionDigits,
            final int maxFractionDigits, final RoundingMode mode) {
        final int scale = number.scale();
        if (scale < minFractionDigits) {
            return number.setScale(minFractionDigits, mode);
        }/*from w  w  w . j  a v a2 s.c  o  m*/
        if (scale > maxFractionDigits) {
            return number.setScale(maxFractionDigits, mode);
        }
        return number;
    }
}

Related

  1. roundDecimals(Float d)
  2. roundDoubleAsBigDecimal(double d, int numberOfDecimals)
  3. roundDown(BigDecimal a)
  4. rounded(BigDecimal amount)
  5. roundHalfUp2Scale(BigDecimal value)
  6. roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode)
  7. roundOff(final BigDecimal amount)
  8. roundPrice(BigDecimal price, BigDecimal ticksize)
  9. roundTo(final BigDecimal bd, final int numberOfDecPlaces, final int finalScale)