Java Double Number Round roundDouble(double d, int places)

Here you can find the source of roundDouble(double d, int places)

Description

Rounds a double to a set number of decimal places

License

Open Source License

Parameter

Parameter Description
d - the double
places - amount of decimal places

Return

double - the rounded double

Declaration

public static double roundDouble(double d, int places) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww w  . ja va  2 s . c  o  m
     * Rounds a double to a set number of decimal places
     * @param d - the double
     * @param places - amount of decimal places
     * @return double - the rounded double
     */
    public static double roundDouble(double d, int places) {
        return Math.round(d * Math.pow(10, (double) places))
                / Math.pow(10, (double) places);
    }
}

Related

  1. roundDiv(double a, double b)
  2. roundDouble(double d)
  3. roundDouble(double d)
  4. roundDouble(double d, int decimals)
  5. roundDouble(double d, int place)
  6. roundDouble(double num, int precision)
  7. roundDouble(double number, int precision)
  8. roundDouble(double pDouble, int pPlaces)
  9. roundDouble(double val, int precision)