Java Double Number Round round(double n, double nd)

Here you can find the source of round(double n, double nd)

Description

round

License

Apache License

Declaration

public static final double round(double n, double nd) 

Method Source Code

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

public class Main {
    public static final double round(double n, double nd) {
        if (isFinite(n) && isFinite(nd)) {
            double sign_n = (n < 0) ? -1 : 1;
            double abs_n = Math.abs(n);
            double factor = Math.pow(10, nd);
            return sign_n * Math.round(abs_n * factor) / factor;
        } else {/*from   w w  w . j  av  a 2  s.co  m*/
            return Double.NaN;
        }
    }

    public static final boolean isFinite(double x) {
        return !(Double.isInfinite(x) || Double.isNaN(x));
    }
}

Related

  1. Round(double d, int Rpl)
  2. round(double dValue)
  3. round(double input)
  4. round(double input, double step)
  5. round(double n)
  6. round(Double num)
  7. round(double num)
  8. round(double num, int bit)
  9. round(double num, int decimal)