Here you can find the source of formatDoubleString(double data, String pattern)
public static String formatDoubleString(double data, String pattern)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String formatDoubleString(double data, String pattern) { DecimalFormat format = new DecimalFormat(pattern); if (data < 0) { return "0"; }/*from w w w . j a v a 2s. c o m*/ if ((int) (data * 10) == (int) (data) * 10) { return (int) data + ""; } else { return format.format(data); } } }