Here you can find the source of roundToDecimals(double input, int places)
public static double roundToDecimals(double input, int places)
//package com.java2s; public class Main { public static double roundToDecimals(double input, int places) { double log10 = Math.log10(input); // 15000 => 4.xxx double intLog10 = Math.floor(log10); double scale = Math.pow(10, intLog10 - places + 1); double factored = Math.round(input / scale) * scale; // System.out.println("###\t" +input + "\t" + factored); return factored; }/*from w ww .j av a 2 s . co m*/ }