Here you can find the source of decimalFormat(double value, int decimalCnt)
Parameter | Description |
---|---|
value | a parameter |
decimalCnt | a parameter |
public static String decimalFormat(double value, int decimalCnt)
//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; } }