Here you can find the source of round(double d)
public static double round(double d)
//package com.java2s; //License from project: Open Source License public class Main { /** Rounds the number to 4 significant digits */ public static double round(double d) { if (d == 0.0) return d; int digits = (int) (Math.log(d) / Math.log(10)); return round(d, 3 - digits); }//from w ww.j a v a2s . c om /** Rounds the number to n decimal places */ public static double round(double d, int n) { double shift = Math.pow(10, n); return ((double) ((long) (d * shift + 0.5))) / shift; } }