Here you can find the source of round(double unrounded, int precision)
public static String round(double unrounded, int precision)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.text.DecimalFormat; public class Main { public static String round(double unrounded, int precision) { DecimalFormat df = new DecimalFormat("####0.##########"); BigDecimal bd = new BigDecimal(unrounded); BigDecimal rounded = bd.setScale(precision, BigDecimal.ROUND_HALF_UP); return df.format(rounded.doubleValue()); }/*from w w w .j a va2s.c o m*/ }