Here you can find the source of formatDouble(double value)
public static String formatDouble(double value)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { protected static final NumberFormat formatter = new DecimalFormat("###.###"); public static String formatDouble(double value) { return formatter.format(value); }//from w w w. j a va2 s . c o m public static String formatDouble(double value, int n) { StringBuilder str = new StringBuilder("###."); for (int nn = 0; nn < n; nn++) { str.append("#"); } NumberFormat newFormatter = new DecimalFormat(str.toString()); return newFormatter.format(value); } }