Java Double Number Format formatDouble(double v, int decimalPlaces)

Here you can find the source of formatDouble(double v, int decimalPlaces)

Description

format Double

License

Open Source License

Declaration

public static String formatDouble(double v, int decimalPlaces) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatDouble(double v, int decimalPlaces) {
        String ret = String.valueOf(v);
        int i = ret.indexOf(".");
        if (ret.length() > i + decimalPlaces + 1)
            ret = ret.substring(0, i + decimalPlaces + 1);
        else/*from  w  w w .ja v  a  2s . c  om*/
            ret += "0000000000".substring(0, i + decimalPlaces + 1 - ret.length());
        return ret;
    }
}

Related

  1. formatDouble(double d, int precision)
  2. formatDouble(double inDouble, boolean inComma, int inCommaPos)
  3. formatDouble(double num, int width, int precision)
  4. FormatDouble(double p_value, int p_numberOfDecimalPlaces)
  5. formatDouble(double source, int decimals, int precision)
  6. formatDouble(double val)
  7. formatDouble(double val)
  8. formatDouble(double val, int prec)
  9. formatDouble(double val, int precision)