Here you can find the source of round(double d, int decimals)
public static double round(double d, int decimals)
//package com.java2s; //License from project: Apache License public class Main { public static double round(double d, int decimals) { if (d != d) { return Double.NaN; }//from w w w.ja v a 2 s .c o m double n = Math.pow(10, decimals); return Math.round(d * n) / n; } public static double round(double d, double fraction) { if (d != d) { return Double.NaN; } return Math.round(d * fraction) / fraction; } }