Java Double Number Format getFormattedString(double d, int numDecimalPlaces)

Here you can find the source of getFormattedString(double d, int numDecimalPlaces)

Description

get Formatted String

License

Open Source License

Declaration

public static String getFormattedString(double d, int numDecimalPlaces) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    public static String getFormattedString(double d, int numDecimalPlaces) {
        StringBuilder sb = new StringBuilder();
        sb.append("##.");

        for (int i = 0; i < numDecimalPlaces; i++)
            sb.append("#");

        DecimalFormat df = new DecimalFormat(sb.toString());
        return df.format(d);
    }// ww w.  j  a  v a 2  s.co  m
}

Related

  1. formatDoubleWithPadding(String value, int length, char pad)
  2. getFormat(double d)
  3. getFormat(double value)
  4. getFormatAmount(Double d)
  5. getFormattedNumber(Double number, int decimals, Locale locale)
  6. getFormattedTwoDecimal(double d)
  7. getFormattedValue(double argDoubleValue)
  8. getTwoDecimalByDecimalFormat(double number)
  9. getValidString(Double value, DecimalFormat formatter)