Here you can find the source of format(double number)
public static String format(double number)
//package com.java2s; import java.text.DecimalFormat; public class Main { public static String format(double number, int digits) { String pattern = "0."; for (int i = 0; i < digits; i++) { pattern += "0"; }/* w w w .j a v a 2 s . co m*/ DecimalFormat format = new DecimalFormat(pattern); return format.format(number); } public static String format(double number) { if (number == (int) number) return String.valueOf((int) number); else return String.valueOf(number); } }