Here you can find the source of round(double val)
public static double round(double val)
//package com.java2s; //License from project: Open Source License public class Main { public static double round(double val) { int precision = 10000; //keep 4 digits return Math.floor(val * precision + .5) / precision; }//from w ww. ja v a 2 s .com public static double round(float val) { int precision = 10000; //keep 4 digits return Math.floor(val * precision + .5) / precision; } public static double round(double val, int n) { int precision = 1; for (int i = 0; i < n; i++) precision *= 10; return Math.floor(val * precision + .5) / precision; } public static float round(float val, int n) { int precision = 1; for (int i = 0; i < n; i++) precision *= 10; return (float) (Math.floor(val * precision + .5) / precision); } }