Here you can find the source of roundToNthDecimal(double number, int decimals)
public static double roundToNthDecimal(double number, int decimals)
//package com.java2s; //License from project: Open Source License public class Main { public static double roundToNthDecimal(double number, int decimals) { return roundToNearest(number * Math.pow(10, decimals)) / Math.pow(10, decimals); }/*from w ww . ja v a 2 s. c o m*/ public static double roundToNearest(double number) { if ((int) (number + .5) >= (int) (number)) return (int) number + 1; return (int) number; } }