Here you can find the source of isDivisible(Double a, int b, int decimal)
public static boolean isDivisible(Double a, int b, int decimal)
//package com.java2s; import java.math.BigDecimal; public class Main { public static boolean isDivisible(Double a, int b, int decimal) { boolean result = false; Double divideValue = divide(a.toString(), String.valueOf(b), 5, BigDecimal.ROUND_HALF_UP).doubleValue(); String divideStr = divideValue.toString(); String remainder = divideStr.substring(divideStr.lastIndexOf(".") + 1); if ("0".equals(remainder)) { result = true;/* w ww. j a v a 2s. c o m*/ } else { result = remainder.length() == decimal; } return result; } /** * Double divide * @param a * @param b * @return * @Create Sin@2012/2/23 */ public static BigDecimal divide(String a, String b, int scale, int roundMode) { BigDecimal bd1 = new BigDecimal(a); BigDecimal bd2 = new BigDecimal(b); return bd1.divide(bd2, scale, roundMode); } public static Double divide(Double a, Double b, int scale, int roundMode) throws Exception { BigDecimal bd1 = new BigDecimal(a.toString()); BigDecimal bd2 = new BigDecimal(b.toString()); return bd1.divide(bd2, scale, roundMode).doubleValue(); } public static Double divide(Double a, Double b) { BigDecimal bd1 = new BigDecimal(a.toString()); BigDecimal bd2 = new BigDecimal(b.toString()); return bd1.divide(bd2).doubleValue(); } }