Java Double Number Round round(double d, int decimals)

Here you can find the source of round(double d, int decimals)

Description

round

License

Apache License

Declaration

public static double round(double d, int decimals) 

Method Source Code

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

public class Main {
    public static double round(double d, int decimals) {
        if (d != d) {
            return Double.NaN;
        }//from w  w  w.ja v  a 2 s .c o m
        double n = Math.pow(10, decimals);
        return Math.round(d * n) / n;
    }

    public static double round(double d, double fraction) {
        if (d != d) {
            return Double.NaN;
        }
        return Math.round(d * fraction) / fraction;
    }
}

Related

  1. round(double d)
  2. round(double d)
  3. round(double d)
  4. round(double d)
  5. round(double d, int decimalPlacesRequired)
  6. round(double d, int i)
  7. round(double d, int numDecimal)
  8. round(double d, int p)
  9. round(double d, int precision)