Java Double Number Round round(double val, int places)

Here you can find the source of round(double val, int places)

Description

round

License

Open Source License

Declaration

public static double round(double val, int places) 

Method Source Code

//package com.java2s;

public class Main {
    public static double round(double val, int places) {
        long factor = (long) Math.pow(10, places);

        //         Shift the decimal the correct number of places
        //         to the right.
        val = val * factor;

        //         Round to the nearest integer.
        long tmp = Math.round(val);

        //         Shift the decimal the correct number of places
        //         back to the left.
        return (double) tmp / factor;
    }//from  w ww  .ja v a  2  s . c o m

    public static float round(float val, int places) {
        return (float) round((double) val, places);
    }
}

Related

  1. round(double val)
  2. round(double val)
  3. round(double val, int decimalHouses)
  4. round(double val, int decimalPlaces)
  5. round(double val, int places)
  6. round(double val, int places)
  7. round(double val, long dec)
  8. round(double valor)
  9. round(double value)