Here you can find the source of decimalRound(BigDecimal number, int numDigits, RoundingMode rounding)
public static BigDecimal decimalRound(BigDecimal number, int numDigits, RoundingMode rounding)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /**//ww w . ja va 2 s. c o m * Rounding for decimals with support for negative digits */ public static BigDecimal decimalRound(BigDecimal number, int numDigits, RoundingMode rounding) { BigDecimal rounded = number.setScale(numDigits, rounding); if (numDigits < 0) { rounded = rounded.setScale(0, BigDecimal.ROUND_UNNECESSARY); } return rounded; } }