Here you can find the source of roundDouble(double num, int precision)
public static double roundDouble(double num, int precision)
//package com.java2s; public class Main { public static double roundDouble(double num, int precision) { return ((double) Math.round(num * pow(10, precision))) / (pow(10, precision)); }//from w ww .j av a 2s .c om public static double pow(double base, int exp) { return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1); } public static long pow(long base, int exp) { return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1); } public static int pow(int base, int exp) { return exp == 0 ? 1 : sq(pow(base, exp / 2)) * (exp % 2 == 1 ? base : 1); } private static double sq(double x) { return x * x; } private static long sq(long x) { return x * x; } private static int sq(int x) { return x * x; } }