Here you can find the source of formatDouble(Double num)
public static String formatDouble(Double num)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { public static String formatDouble(Double num) { NumberFormat numberFormat = NumberFormat.getInstance(); if ((num % 1) == 0) { numberFormat.setMaximumFractionDigits(0); return numberFormat.format(num); } else {/*from w w w .j av a2s . c o m*/ numberFormat.setMaximumFractionDigits(2); return numberFormat.format(num); } } }