Java Double Number Round round(double a, int decimal)

Here you can find the source of round(double a, int decimal)

Description

round

License

Open Source License

Declaration

public static final double round(double a, int decimal) 

Method Source Code

//package com.java2s;

public class Main {
    public static final double round(double a, int decimal) {
        try {/* w  ww.  j av  a  2  s . c om*/
            String str = String.valueOf(a);
            int idx = str.indexOf(".");
            if (idx == -1 || idx == str.length() - 1)
                return Double.parseDouble(str);
            return Double.parseDouble(str.substring(0, Math.min(str.length(), idx + decimal + 1)));
        } catch (Exception e) {
            System.out.println("There is some error MathUtil.round: " + e.getMessage());
            return 0;
        }
    }
}

Related

  1. round(double a)
  2. round(double a)
  3. Round(double a)
  4. round(double a, double precision)
  5. round(double a, int cutOfDigits)
  6. round(double a, int rounding_style)
  7. round(double amount)
  8. round(double amt, int digits)
  9. round(double d)