Here you can find the source of roundDouble(double number, int precision)
Parameter | Description |
---|---|
number | Number to round |
precision | The precision of rounding |
public static double roundDouble(double number, int precision)
//package com.java2s; public class Main { /**//w ww. jav a 2 s . co m * Returns the rounded double number with a given precision. * * @param number Number to round * @param precision The precision of rounding * @return Rounded double with a given precision. */ public static double roundDouble(double number, int precision) { int temp = (int) ((number * Math.pow(10, precision))); return (((double) temp) / Math.pow(10, precision)); } }