Here you can find the source of round(BigDecimal initData, int scale)
public static BigDecimal round(BigDecimal initData, int scale)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { public static double round(double v, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }/*from w w w . ja v a 2 s.c o m*/ BigDecimal b = new BigDecimal(Double.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } public static BigDecimal round(BigDecimal initData, int scale) { if (initData == null) { return null; } return initData.setScale(scale, BigDecimal.ROUND_HALF_UP); } }