Here you can find the source of round(double val, int numberOfDigitsAfterDecimal)
public static double round(double val, int numberOfDigitsAfterDecimal)
//package com.java2s; public class Main { public static double round(double val, int numberOfDigitsAfterDecimal) { double p = (float) Math.pow(10, numberOfDigitsAfterDecimal); val = val * p; double tmp = Math.floor(val); return (double) tmp / p; }//from www . j a v a 2s. c o m }