Java tutorial
//package com.java2s; import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /** * Round double value with low error * * @param value Value * @param places decimal * @return double */ static double round(double value, int places) { // check if places below 0 places = Math.max(0, places); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); } }