Here you can find the source of div(BigDecimal d1, BigDecimal d2)
public static BigDecimal div(BigDecimal d1, BigDecimal d2)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { private static final int DEF_DIV_SCALE = 5; public static double div(double d1, double d2) { return div(d1, d2, DEF_DIV_SCALE); }// ww w . j a v a 2s. c o m public static BigDecimal div(BigDecimal d1, BigDecimal d2) { return div(d1, d2, DEF_DIV_SCALE); } public static double div(double d1, double d2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } BigDecimal b1 = new BigDecimal(Double.toString(d1)); BigDecimal b2 = new BigDecimal(Double.toString(d2)); return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } public static BigDecimal div(BigDecimal d1, BigDecimal d2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } return d1.divide(d2, scale, BigDecimal.ROUND_HALF_UP); } }