Here you can find the source of toDecimalString(String str, int decimal)
public static String toDecimalString(String str, int decimal)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String toDecimalString(String str, int decimal) { if (null == str) { return ""; }/*from w ww .j av a 2s . co m*/ return toDecimalString(Double.valueOf(str.trim()), decimal); } public static String toDecimalString(Double num, int decimal) { if (num == null) { return ""; } String str = num.toString(); String formatStr = "#."; for (int i = 0; i < decimal; ++i) { formatStr = formatStr + "0"; } DecimalFormat df = new DecimalFormat(formatStr); try { str = df.format(num); } catch (Exception localException) { } return str; } }