Java BigDecimal Round round_BigDecimal(double d, int decLen)

Here you can find the source of round_BigDecimal(double d, int decLen)

Description

roun Big Decimal

License

Apache License

Declaration

private static double round_BigDecimal(double d, int decLen) 

Method Source Code


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

import java.math.BigDecimal;

public class Main {
    private static double round_BigDecimal(double d, int decLen) {
        BigDecimal bigD = new BigDecimal(d);
        if (decLen < 0) {
            double tempValue = bigD.movePointLeft(-decLen).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
            bigD = (new BigDecimal(tempValue)).movePointRight(-decLen);
        } else {/*  w ww . j a v a  2 s .  c o  m*/
            bigD = bigD.setScale(decLen, BigDecimal.ROUND_HALF_UP);
        }
        return bigD.doubleValue();
    }
}

Related

  1. round(BigDecimal value, int places)
  2. round(BigDecimal value, String currency)
  3. round(BigDecimal what, int howmuch)
  4. round(final BigDecimal input, final int precision)
  5. round(final BigDecimal number, final int minFractionDigits, final int maxFractionDigits, final RoundingMode roundingMode)
  6. roundBigDecimal(BigDecimal num)
  7. roundBigDecimal(Number value, double precision)
  8. roundCommercial(BigDecimal value, int decimalPlaces)
  9. roundDecimal(Object value)