Here you can find the source of round(double val, int places)
public static double round(double val, int places)
//package com.java2s; public class Main { public static double round(double val, int places) { long factor = (long) Math.pow(10, places); // Shift the decimal the correct number of places // to the right. val = val * factor; // Round to the nearest integer. long tmp = Math.round(val); // Shift the decimal the correct number of places // back to the left. return (double) tmp / factor; }//from w ww .ja v a 2 s . c o m public static float round(float val, int places) { return (float) round((double) val, places); } }