Here you can find the source of numberToFormattedString(Double d)
private static String numberToFormattedString(Double d)
//package com.java2s; //License from project: BSD License public class Main { private static String numberToFormattedString(Double d) { String s = d.toString();/*from w ww.j a va2 s .c o m*/ if (s.endsWith(".0")) { return s.substring(0, s.length() - 2); } else if (s.length() > 7) { return String.format("%.6g", d); } else { return s; } } }