Java tutorial
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { private static final int DEF_DIV_SCALE = 10; public static double divide(double v1, double v2) { return divide(v1, v2, DEF_DIV_SCALE); } public static double divide(double v1, double v2, int scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); } BigDecimal b = new BigDecimal(Double.toString(v1)); BigDecimal one = new BigDecimal(v2); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } }