Java Number Format Pattern CreateDecimalFormat(int numberOfDecimalsDisplayed)

Here you can find the source of CreateDecimalFormat(int numberOfDecimalsDisplayed)

Description

Gets the amount of decimals that should be displayed with a DecimalFormat object.

License

Open Source License

Declaration

public static DecimalFormat CreateDecimalFormat(int numberOfDecimalsDisplayed) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    /**//from   w  ww.  j  a v a 2  s. com
     * Gets the amount of decimals that should be displayed with a DecimalFormat object.
     * @return
     */
    public static DecimalFormat CreateDecimalFormat(int numberOfDecimalsDisplayed) {
        if (numberOfDecimalsDisplayed < 1)
            return new DecimalFormat("#");

        String format = "#.";
        for (int i = 1; i <= numberOfDecimalsDisplayed; i++)
            format += "#";

        return new DecimalFormat(format);
    }
}

Related

  1. countFormat(int no)
  2. createDecimalFormat(final String pattern)
  3. createDecimalFormat(String pattern)
  4. createDecimalFormatter(String pattern)
  5. createNumberFormat()
  6. createNumberFormat(int cnt)