Here you can find the source of formatDoubleToString(double n)
public static String formatDoubleToString(double n)
//package com.java2s; //License from project: Open Source License public class Main { public final static String format = "%.4f"; public static String formatDoubleToString(double n) { String s = String.format(format, n); while (s.charAt(s.length() - 1) == '0') { s = s.substring(0, s.length() - 1); }//from w ww . j av a 2s . com if (s.charAt(s.length() - 1) == '.') { s = s.substring(0, s.length() - 1); } return s; } }