Here you can find the source of round(BigDecimal num, int scale)
public static BigDecimal round(BigDecimal num, int scale)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { public static BigDecimal round(BigDecimal num, int scale) { return num.divide(new BigDecimal("1"), scale, BigDecimal.ROUND_HALF_UP); }//from w w w .j av a2 s.c o m public static BigDecimal round(String num, int scale) { num = checkNum(num); BigDecimal bd1 = new BigDecimal(num); return bd1.divide(new BigDecimal("1"), scale, BigDecimal.ROUND_HALF_UP); } public static BigDecimal divide(String num1, String num2, int scale) { num1 = checkNum(num1); if ("".equals(num2)) { num2 = "1"; } BigDecimal bd1 = new BigDecimal(num1); BigDecimal bd2 = new BigDecimal(num2); return bd1.divide(bd2, scale, BigDecimal.ROUND_HALF_UP); } private static String checkNum(String num) { if ("".equals(num)) { num = "0"; } return num; } }