Here you can find the source of formatDouble(double d)
public static String formatDouble(double d)
//package com.java2s; /*//from w ww . j a va 2 s .co m (C) 2007 Stefan Reich (jazz@drjava.de) This source file is part of Project Prophecy. For up-to-date information, see http://www.drjava.de/prophecy This source file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1. */ import java.text.*; public class Main { public static String formatDouble(double d) { return /*Double.toString(d)*/formatDouble(d, 4); } public static String formatDouble(double d, int digits) { String format = "0."; for (int i = 0; i < digits; i++) format += "#"; String s = new DecimalFormat(format).format(d); return s.replace(',', '.'); // hack german -> english } public static String replace(String pattern, String substitute, String s) { StringBuffer buf = new StringBuffer(); while (true) { int i = s.indexOf(pattern); if (i >= 0) { buf.append(s.substring(0, i)); buf.append(substitute); s = s.substring(i + pattern.length()); } else { buf.append(s); break; } } return buf.toString(); } }