Here you can find the source of round_BigDecimal(double d, int decLen)
private static double round_BigDecimal(double d, int decLen)
//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(); } }