Here you can find the source of getRoundedBigDecimal(double value, int scale)
public static BigDecimal getRoundedBigDecimal(double value, int scale)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.math.RoundingMode; public class Main { public static final int NUMBER_DECIMAL_PLACES = 4; public static BigDecimal getRoundedBigDecimal(double value, int scale) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(scale, RoundingMode.HALF_UP); return bd; }//from w w w . j av a 2 s . c o m /** * Get a big decimal rounded out to NUMBER_DECIMAL_PLACES places * from the supplied double. * * @param value * @return */ public static BigDecimal getRoundedBigDecimal(double value) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(NUMBER_DECIMAL_PLACES, RoundingMode.HALF_UP); return bd; } }