Here you can find the source of divide(double v1, double v2)
public static double divide(double v1, double v2)
//package com.java2s; import java.math.BigDecimal; public class Main { private static final int DEFAULT_DIV_SCALE = 10; public static double divide(double v1, double v2) { return divide(v1, v2, DEFAULT_DIV_SCALE); }/*from ww w . j av a2 s . c o m*/ public static double divide(double v1, double v2, int scale) { return divide(v1, v2, scale, BigDecimal.ROUND_HALF_UP); } public static double divide(double v1, double v2, int scale, int round_mode) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2, scale, round_mode).doubleValue(); } public static String divide(String v1, String v2) { return divide(v1, v2, DEFAULT_DIV_SCALE); } public static String divide(String v1, String v2, int scale) { return divide(v1, v2, scale, BigDecimal.ROUND_HALF_UP); } public static String divide(String v1, String v2, int scale, int round_mode) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.divide(b2, scale, round_mode).toString(); } }