Java Double Number Round roundDoubleToPlace(double d, int place)

Here you can find the source of roundDoubleToPlace(double d, int place)

Description

round Double To Place

License

BSD License

Parameter

Parameter Description
f a parameter
place number of places after decimal point, between 0 and 9

Declaration

public static double roundDoubleToPlace(double d, int place) 

Method Source Code

//package com.java2s;
// LICENSE:      This file is distributed under the BSD license.

public class Main {
    /**/*from  w ww  . j  a  v a2 s .  c  o m*/
     * 
     * @param f
     * @param place number of places after decimal point, between 0 and 9
     * @return
     */
    public static double roundDoubleToPlace(double d, int place) {
        if (place < 0)
            throw new IllegalArgumentException();
        if (place > 9)
            throw new IllegalArgumentException();
        long factor = (long) Math.pow(10, place);
        return ((double) Math.round(d * factor)) / factor;
    }
}

Related

  1. roundDouble3(double r)
  2. roundDoubleDownTo(double value, double steps)
  3. roundDoubleNicely(double intensity)
  4. roundDoubleTo(double val, int pow)
  5. roundDoubleToInt(final double VALUE)
  6. roundDoubleValue(double value)
  7. roundDown(double a)
  8. roundDown(double amt, double digits)
  9. roundDown(double n)