List of utility methods to do BigDecimal Round
BigDecimal | rounded(BigDecimal amount) Rounds an amount to two decimal places. return amount.setScale(DECIMALS, ROUNDING_MODE);
|
Double | roundHalfUp2Scale(BigDecimal value) round Half Up Scale if (value == null) return null; BigDecimal bd = value.setScale(2, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); |
BigDecimal | roundImpl(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode mode) round Impl final int scale = number.scale(); if (scale < minFractionDigits) { return number.setScale(minFractionDigits, mode); if (scale > maxFractionDigits) { return number.setScale(maxFractionDigits, mode); return number; ... |
BigDecimal | roundingError(final BigDecimal dividend, final BigDecimal divisor, final int roundingMode) Calculates the rounding error when dividend is divided by divisor
return dividend.subtract(dividend.divide(divisor, divisor.scale(), roundingMode).multiply(divisor));
|
BigDecimal | roundOff(final BigDecimal amount) This method is a utility method, which takes a BigDecimal and rounds that to 0 places. return amount.setScale(DECIMALS, ROUNDING_MODE);
|
BigDecimal | roundPrice(BigDecimal price, BigDecimal ticksize) Rounds the specified price to the specified tick size return roundPrice(price, ticksize, ticksize.scale());
|
BigDecimal | roundTo(final BigDecimal bd, final int numberOfDecPlaces, final int finalScale) returns a new BigDecimal with correct scale after being round to n dec places. return setScale(setScale(bd, numberOfDecPlaces, BigDecimal.ROUND_HALF_UP), finalScale);
|
BigDecimal | roundToMSDecimal(BigDecimal sourceDecimal) round To MS Decimal BigInteger sourceDecimalIntComponent = sourceDecimal.unscaledValue(); BigDecimal destinationDecimal = new BigDecimal(sourceDecimalIntComponent, sourceDecimal.scale()); byte roundingModel = 4; validateDecimalMinMax(destinationDecimal); BigInteger allWordBigInt = destinationDecimal.unscaledValue(); if (allWordBigInt.bitLength() > 96) { destinationDecimal = destinationDecimal.round(new MathContext(29)); if (allWordBigInt.bitLength() > 96) { ... |
BigDecimal | roundUp1(BigDecimal number) round Up return number.setScale(0, RoundingMode.UP);
|
BigDecimal | valueOfBigDecimalRounding(double d1, int decimalPrecision) value Of Big Decimal Rounding BigDecimal bd = new BigDecimal(d1); MathContext mc = new MathContext(decimalPrecision, RoundingMode.HALF_UP); return bd.round(mc); |