Here you can find the source of divide(Object num1, Object num2)
public static Double divide(Object num1, Object num2)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { private static int DEF_SCALE = 10; public static Double divide(Object num1, Object num2) { return divide(num1, num2, DEF_SCALE); }/*from w w w. j a v a 2 s .co m*/ public static Double divide(Object num1, Object num2, Integer scale) { if (scale == null) { scale = DEF_SCALE; } num2 = num2 == null || Math.abs(new Double(num2.toString())) == 0 ? 1 : num2; if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); } BigDecimal result = bigDecimal(num1).divide(bigDecimal(num2), scale, BigDecimal.ROUND_HALF_UP); return result.doubleValue(); } public static BigDecimal bigDecimal(Object object) { if (object == null) { throw new NullPointerException(); } BigDecimal result; try { result = new BigDecimal(String.valueOf(object).replaceAll(",", "")); } catch (NumberFormatException e) { throw new NumberFormatException("Please give me a numeral.Not " + object); } return result; } }