Java Double Number Round round(double x, int numPlaces)

Here you can find the source of round(double x, int numPlaces)

Description

round

License

Apache License

Declaration

public static double round(double x, int numPlaces) 

Method Source Code

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

public class Main {
    public static double round(double x, int numPlaces) {
        double scale = Math.pow(10, numPlaces);
        return Math.round(x * scale) / scale;
    }//from  w  w  w.ja va 2 s  .c  o m

    public static double[] round(double[] vec, int numPlaces) {
        double[] newVec = new double[vec.length];
        double scale = Math.pow(10, numPlaces);
        for (int i = 0; i < vec.length; i++)
            newVec[i] = Math.round(vec[i] * scale) / scale;
        return newVec;
    }
}

Related

  1. round(double what, int howmuch)
  2. round(double x)
  3. round(double x)
  4. round(double x)
  5. round(double x)
  6. round(double x, int places)
  7. round(double zahl, int stellen)
  8. round(double[] arr)
  9. round(double[] array, int decimals)