Java Decimal Format decimalFormat(double value, int decimalCnt)

Here you can find the source of decimalFormat(double value, int decimalCnt)

Description

 

License

Apache License

Parameter

Parameter Description
value a parameter
decimalCnt a parameter

Declaration

public static String decimalFormat(double value, int decimalCnt) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    /**//from w  w  w . j a v a2  s. c o m
     * <pre>
     * 
     * </pre>
     * 
     * @Date : 2013. 2. 3.
     * @param value
     * @param decimalCnt
     * @return
     */
    public static String decimalFormat(double value, int decimalCnt) {
        String resultValue = "";
        String pattern = "";

        if (decimalCnt > 0) {
            for (int i = 0; i < decimalCnt; i++) {
                pattern += "#";
            }

            pattern = "." + pattern;
            DecimalFormat df = new DecimalFormat(pattern);
            resultValue = df.format(value);
        } else {
            resultValue = String.valueOf(value);
        }

        return resultValue;
    }
}

Related

  1. decimalFormat()
  2. decimalFormat(double d)
  3. decimalFormat(double no)
  4. decimalFormat(double number)
  5. decimalFormat(Double numeric)
  6. decimalFormat(Object obj)
  7. decimalFormat(String pattern)
  8. decimalFormat(String pattern, double value)
  9. decimalFormatLabel(final long value, final long divider, final String unit)