Here you can find the source of round(double x, int numPlaces)
public static double round(double x, int numPlaces)
//package com.java2s; //License from project: Apache License public class Main { public static double round(double x, int numPlaces) { double scale = Math.pow(10, numPlaces); return Math.round(x * scale) / scale; }//from w w w.ja va 2 s .c o m public static double[] round(double[] vec, int numPlaces) { double[] newVec = new double[vec.length]; double scale = Math.pow(10, numPlaces); for (int i = 0; i < vec.length; i++) newVec[i] = Math.round(vec[i] * scale) / scale; return newVec; } }