Java Double Number Round roundDouble(double number, int precision)

Here you can find the source of roundDouble(double number, int precision)

Description

Returns the rounded double number with a given precision.

License

Open Source License

Parameter

Parameter Description
number Number to round
precision The precision of rounding

Return

Rounded double with a given precision.

Declaration

public static double roundDouble(double number, int precision) 

Method Source Code

//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));
    }
}

Related

  1. roundDouble(double d)
  2. roundDouble(double d, int decimals)
  3. roundDouble(double d, int place)
  4. roundDouble(double d, int places)
  5. roundDouble(double num, int precision)
  6. roundDouble(double pDouble, int pPlaces)
  7. roundDouble(double val, int precision)
  8. roundDouble(double value)
  9. roundDouble(double value, int afterDecimalPoint)