Here you can find the source of valueOfBigDecimalRounding(double d1, int decimalPrecision)
public static BigDecimal valueOfBigDecimalRounding(double d1, int decimalPrecision)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; public class Main { public static BigDecimal valueOfBigDecimalRounding(double d1, int decimalPrecision) { BigDecimal bd = new BigDecimal(d1); MathContext mc = new MathContext(decimalPrecision, RoundingMode.HALF_UP); return bd.round(mc); }//w ww.ja v a2 s. c om }