class DecimalUtil {

    public static String toString(double value, int precision) {
        // create decimal format string
        StringBuilder buf = new StringBuilder("0");
        if (precision > 0) {
            buf.append(".");
        }
        for (int i = 0; i < precision; i++) {
            buf.append("0");
        }
        // create a decimal format
        DecimalFormat format = new DecimalFormat(buf.toString());
        return format.format(value);
        
        /**
        String temp = Double.toString(value);
        StringBuffer buf = new StringBuffer(temp.length()+precision);
        buf.append(temp);
        // find the '.' char
        int pos = buf.indexOf(".");
        // was the . found, if not, add it so we can use the same logic below
        if (pos < 0) {
            // if we want precision, add . and set the position correctly
            if (precision > 0) {
                buf.append('.');
                pos = buf.length()-1;   // set pos to last char
            } else {
                return buf.toString();
            }
        }
        // number of digits after
        int digitsAfter = buf.length() - pos - 1;

        // if precision is zero, then fake getting rid of the period by incrementing this
        if (precision == 0)
            digitsAfter++;

        // do we need to add, delete, or keep it?
        if (digitsAfter < precision) {
            // add zeoes
            int count = precision - digitsAfter;
            for (int i = 0; i < count; i++) {
                buf.append('0');
            }
        } else if (digitsAfter > precision) {
            // trim digits
            int count = digitsAfter - precision;
            buf.delete(buf.length()-count, buf.length());
        }
        return buf.toString();
         */
    }

}