Round a double by setting the scale
import java.math.BigDecimal; public class Main { public static void main(String args[]) { double r = 3.1234567; int decimalPlace = 2; BigDecimal bd = new BigDecimal(r); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_UP); r = bd.doubleValue(); System.out.println(r); } }