Java Number Round roundToPrecision(double number, int precision)

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

Description

round To Precision

License

Open Source License

Declaration

public static double roundToPrecision(double number, int precision) 

Method Source Code

//package com.java2s;
/**/* ww w  .  j a v a 2 s  .c  om*/
 * NumericImpl contains logic for numeric data. This implementation is referred to YUI's NumericImpl.js which license under
 * BSD License. - http://yuilibrary.com/license/
 * @author jumperchen
 *
 */

public class Main {
    public static double roundToPrecision(double number, int precision) {
        double decimalPlaces = Math.pow(10, precision);
        return Math.round(decimalPlaces * number) / decimalPlaces;
    }
}

Related

  1. roundToNthDecimal(double number, int decimals)
  2. roundToNumDigits(double d, int n)
  3. roundToPowerOf(int i, int powerOf)
  4. roundToPowerOf10(double value, int powerOf10)
  5. roundToPowerOf2(int value)
  6. roundToPrecision(float value, int numDecimalPlaces)
  7. roundToQuarterMs(float f)
  8. roundToShort(final double d)
  9. roundToSignificantDigits(double num, int n)