Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String getDecimal(double decimal, int length) { String strLen = "."; if (length <= 0) { strLen = ""; } else { for (int i = 0; i < length; i++) { strLen += "0"; } } java.text.DecimalFormat df = new java.text.DecimalFormat("0" + strLen); return df.format(decimal); } }