Java Number Round roundToDecimals(double input, int places)

Here you can find the source of roundToDecimals(double input, int places)

Description

round To Decimals

License

Open Source License

Declaration

public static double roundToDecimals(double input, int places) 

Method Source Code

//package com.java2s;

public class Main {
    public static double roundToDecimals(double input, int places) {
        double log10 = Math.log10(input); // 15000 => 4.xxx
        double intLog10 = Math.floor(log10);
        double scale = Math.pow(10, intLog10 - places + 1);
        double factored = Math.round(input / scale) * scale;
        // System.out.println("###\t" +input + "\t" + factored);
        return factored;
    }/*from   w  ww  .j av  a  2 s .  co  m*/
}

Related

  1. roundToDecimals(double d, int c)
  2. roundToDecimals(double d, int c)
  3. roundToDecimals(double d, int numberOfDecimalPlaces)
  4. roundToDecimals(double d, int percision)
  5. roundToDecimals(double doubleValue)
  6. roundToDefaultPrecision(final double value)
  7. roundToDimensions(int value, int f)
  8. roundToDimensions(int value, int nearestValue)
  9. roundToEight(long i)