Java Double Number Round round(double value, int precision)

Here you can find the source of round(double value, int precision)

Description

Round a double up or down by the given number of decimal places

License

Apache License

Parameter

Parameter Description
value a parameter
precision a parameter

Declaration

public static double round(double value, int precision) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//ww w.  j a v a  2 s .  c  om
     * Round a double up or down by the given number of decimal places
     *
     * @param value
     * @param precision
     * @return
     */
    public static double round(double value, int precision) {
        double factor = Math.pow(10, precision);
        double result = Math.round(value * factor) / factor;

        return result;
    }
}

Related

  1. round(double value, int numDecimals)
  2. round(double value, int places)
  3. round(double value, int places)
  4. round(double value, int power)
  5. round(double value, int precision)
  6. round(double value, int precision)
  7. round(double value, int roundingFactor)
  8. round(double value, int scalar, int standard)
  9. round(double valueToRound, int numberOfDecimalPlaces)